@@ -6,21 +6,21 @@ namespace SysadminsLV.Asn1Parser;
66static class StringToBinaryFormatter {
77 static readonly Char [ ] _delimiters = [ ' ' , '-' , ':' , '\t ' , '\n ' , '\r ' ] ;
88
9- public static Byte [ ] FromBase64 ( String input ) {
9+ public static Byte [ ] ? FromBase64 ( String input ) {
1010 try {
1111 return Convert . FromBase64String ( input . Trim ( ) ) ;
1212 } catch {
1313 return null ;
1414 }
1515 }
1616 // accept any header, not only certificate
17- public static Byte [ ] FromBase64Header ( String input ) {
17+ public static Byte [ ] ? FromBase64Header ( String input ) {
1818 const String header = "-----BEGIN " ;
1919 const String footer = "-----END " ;
2020
2121 return FromBase64Header ( input , header , footer , true ) ;
2222 }
23- public static Byte [ ] FromBase64Header ( String input , String header , String footer , Boolean skipHeaderValidation = false ) {
23+ public static Byte [ ] ? FromBase64Header ( String input , String header , String footer , Boolean skipHeaderValidation = false ) {
2424 if ( skipHeaderValidation && ( ! input . ToUpper ( ) . Contains ( header ) || ! input . Contains ( footer ) ) ) {
2525 return null ;
2626 }
@@ -33,7 +33,7 @@ public static Byte[] FromBase64Header(String input, String header, String footer
3333 return null ;
3434 }
3535 }
36- public static Byte [ ] FromBase64Request ( String input ) {
36+ public static Byte [ ] ? FromBase64Request ( String input ) {
3737 String header ;
3838 String footer ;
3939 if ( input . ToUpper ( ) . Contains ( PemHeader . PEM_HEADER_REQ_NEW . GetHeader ( ) ) ) {
@@ -48,7 +48,7 @@ public static Byte[] FromBase64Request(String input) {
4848
4949 return FromBase64Header ( input , header , footer , true ) ;
5050 }
51- public static Byte [ ] FromBinary ( String input ) {
51+ public static Byte [ ] ? FromBinary ( String input ) {
5252 Byte [ ] rawBytes = new Byte [ input . Length ] ;
5353 for ( Int32 i = 0 ; i < input . Length ; i ++ ) {
5454 try {
@@ -62,7 +62,7 @@ public static Byte[] FromBinary(String input) {
6262 * 1) hex octet must be paired with hex chars, e.g. 0f, 08, not 8, f.
6363 * 2) each octet is separated by one or more delimiter chars
6464 */
65- public static Byte [ ] FromHex ( String input ) {
65+ public static Byte [ ] ? FromHex ( String input ) {
6666 var bytes = new List < Byte > ( input . Length / 2 ) ;
6767 for ( Int32 i = 0 ; i < input . Length ; i ++ ) {
6868 if ( testHexChar ( input [ i ] ) ) {
@@ -84,7 +84,7 @@ public static Byte[] FromHex(String input) {
8484 * 4) next address field may appear only when 16 octets are calculated in previous line.
8585 * 5) address field may be the only field in the line.
8686 */
87- public static Byte [ ] FromHexAddr ( String input ) {
87+ public static Byte [ ] ? FromHexAddr ( String input ) {
8888 Byte octetCount = 0 ;
8989 Boolean addressReached = false ;
9090 var bytes = new List < Byte > ( input . Length / 3 ) ;
@@ -162,7 +162,7 @@ public static Byte[] FromHexAddr(String input) {
162162 * 9) invalidate string if any non-whitespace occured after EOF.
163163 * 10) ascii char count must be less or equals to octetCount
164164 */
165- public static Byte [ ] FromHexAscii ( String input ) {
165+ public static Byte [ ] ? FromHexAscii ( String input ) {
166166 Byte octetCount = 0 ;
167167 Boolean asciiReached = false ;
168168 String ascii = String . Empty ;
@@ -227,7 +227,7 @@ public static Byte[] FromHexAscii(String input) {
227227 /* Rules:
228228 * same for 'fromHexAddr' and 'fromHexAddrAscii'
229229 */
230- public static Byte [ ] FromHexAddrAscii ( String input ) {
230+ public static Byte [ ] ? FromHexAddrAscii ( String input ) {
231231 Byte octetCount = 0 ;
232232 Boolean addressReached = false , asciiReached = false ;
233233 String ascii = String . Empty ;
@@ -321,13 +321,13 @@ public static Byte[] FromHexAddrAscii(String input) {
321321 return bytes . ToArray ( ) ;
322322 }
323323
324- public static Byte [ ] FromBase64Any ( String input ) {
324+ public static Byte [ ] ? FromBase64Any ( String input ) {
325325 return FromBase64Header ( input ) ?? FromBase64 ( input ) ;
326326 }
327327 public static Byte [ ] FromStringAny ( String input ) {
328328 return FromBase64Header ( input ) ?? FromBase64 ( input ) ?? input . Select ( Convert . ToByte ) . ToArray ( ) ;
329329 }
330- public static Byte [ ] FromHexAny ( String input ) {
330+ public static Byte [ ] ? FromHexAny ( String input ) {
331331 return FromHexAddr ( input ) ??
332332 FromHexAddrAscii ( input ) ??
333333 FromHex ( input ) ??
0 commit comments