@@ -14,20 +14,18 @@ You may obtain a copy of the License at
1414 See the License for the specific language governing permissions and
1515 limitations under the License.
1616 */
17- using System ;
18- using System . Reflection ;
19- using System . Collections . Generic ;
2017using org . bn . utils ;
21- using org . bn . attributes ;
22- using org . bn . attributes . constraints ;
18+ using System ;
19+ using System . IO ;
20+ using System . Text ;
2321
2422namespace org . bn . coders . per
2523{
2624
2725 public class PERUnalignedDecoder : PERAlignedDecoder
2826 {
2927
30- protected override void skipAlignedBits ( System . IO . Stream stream )
28+ protected override void skipAlignedBits ( Stream stream )
3129 {
3230 // Do nothing! Unaligned encoding ;)
3331 }
@@ -43,48 +41,49 @@ protected override long decodeConstraintNumber(long min, long max, BitArrayInput
4341 {
4442 return max ;
4543 }
46- //For the UNALIGNED variant the value is always encoded in the minimum
44+ // For the UNALIGNED variant the value is always encoded in the minimum
4745 // number of bits necessary to represent the range (defined in 10.5.3).
4846 int currentBit = maxBitLen ;
4947 while ( currentBit > 7 )
5048 {
5149 currentBit -= 8 ;
52- result |= stream . ReadByte ( ) << currentBit ;
50+ result |= ( uint ) ( stream . ReadByte ( ) << currentBit ) ;
5351 }
5452 if ( currentBit > 0 )
5553 {
56- result |= stream . readBits ( currentBit ) ;
54+ result |= ( uint ) stream . readBits ( currentBit ) ;
5755 }
5856 result += min ;
5957 return result ;
6058 }
6159
62- public override DecodedObject < object > decodeString ( DecodedObject < object > decodedTag , System . Type objectClass , ElementInfo elementInfo , System . IO . Stream stream )
60+ public override DecodedObject < object > decodeString ( DecodedObject < object > decodedTag , Type objectClass , ElementInfo elementInfo , Stream stream )
6361 {
64- if ( ! PERCoderUtils . is7BitEncodedString ( elementInfo ) )
62+ if ( ! PERCoderUtils . is7BitEncodedString ( elementInfo ) )
63+ {
6564 return base . decodeString ( decodedTag , objectClass , elementInfo , stream ) ;
66- else
67- {
65+ }
66+ else
67+ {
6868 DecodedObject < object > result = new DecodedObject < object > ( ) ;
6969 int strLen = decodeLength ( elementInfo , stream ) ;
70-
7170 if ( strLen <= 0 )
7271 {
73- result . Value = ( "" ) ;
74- return result ;
72+ result . Value = "" ;
73+ }
74+ else
75+ {
76+ BitArrayInputStream bitStream = ( BitArrayInputStream ) stream ;
77+ // 7-bit decoding of string
78+ byte [ ] buffer = new byte [ strLen ] ;
79+ for ( int i = 0 ; i < strLen ; i ++ )
80+ {
81+ buffer [ i ] = ( byte ) bitStream . readBits ( 7 ) ;
82+ }
83+ result . Value = new string ( ASCIIEncoding . ASCII . GetChars ( buffer ) ) ;
7584 }
76-
77- BitArrayInputStream bitStream = ( BitArrayInputStream ) stream ;
78- byte [ ] buffer = new byte [ strLen ] ;
79- // 7-bit decoding of string
80- for ( int i = 0 ; i < strLen ; i ++ )
81- buffer [ i ] = ( byte ) bitStream . readBits ( 7 ) ;
82- result . Value = new string (
83- System . Text . ASCIIEncoding . ASCII . GetChars ( buffer )
84- ) ;
8585 return result ;
86- }
87-
86+ }
8887 }
8988 }
9089}
0 commit comments