Skip to content

Commit 64f5b0b

Browse files
committed
addressed nullable context compiler warnings
1 parent 8cec2a5 commit 64f5b0b

File tree

11 files changed

+29
-28
lines changed

11 files changed

+29
-28
lines changed

Asn1Parser/Asn1Builder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ public static Asn1Builder Create() {
659659
/// </summary>
660660
/// <param name="rawData">ASN.1-encoded data to initialize the builder from.</param>
661661
/// <returns>ASN.1 Builder.</returns>
662-
public static Asn1Builder Create(Byte[] rawData) {
662+
public static Asn1Builder Create(IEnumerable<Byte> rawData) {
663663
var builder = new Asn1Builder();
664664
builder._rawData.AddRange(rawData);
665665

Asn1Parser/Asn1Reader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Asn1Reader(Byte[] rawData) : this(rawData, 0) { }
8484
/// <summary>
8585
/// Gets current structure tag name.
8686
/// </summary>
87-
public String TagName { get; private set; }
87+
public String TagName { get; private set; } = String.Empty;
8888
/// <summary>
8989
/// Gets current structure full length. Full length contains tag, tag length byte (or bytes) and tag payload.
9090
/// </summary>
@@ -120,7 +120,7 @@ public Asn1Reader(Byte[] rawData) : this(rawData, 0) { }
120120
/// <exception cref="IndexOutOfRangeException"><strong>index</strong> parameter is outside of binary array boundaries.</exception>
121121
public Byte this[Int32 index] => _rawData[index];
122122

123-
void decode(Byte[] raw, Int32 pOffset) {
123+
void decode(Byte[]? raw, Int32 pOffset) {
124124
IsConstructed = false;
125125
childCount = 0;
126126
if (raw != null) {
@@ -441,7 +441,7 @@ public void MoveNextAndExpectTags(params Byte[] expectedTags) {
441441
/// <strong>expectedTags</strong> parameter.
442442
/// </exception>
443443
public void MoveNextAndExpectTags(params Asn1Type[] expectedTags) {
444-
moveAndExpectTypes(MoveNext, expectedTags?.Select(x => (Byte)x).ToArray());
444+
moveAndExpectTypes(MoveNext, expectedTags.Select(x => (Byte)x).ToArray());
445445
}
446446
/// <summary>
447447
/// Moves over current type to the next type at the same level. If the current type is a
@@ -501,7 +501,7 @@ public void MoveNextSiblingAndExpectTags(params Byte[] expectedTags) {
501501
/// specified in the <strong>expectedTags</strong> parameter.
502502
/// </exception>
503503
public void MoveNextSiblingAndExpectTags(params Asn1Type[] expectedTags) {
504-
moveAndExpectTypes(MoveNextSibling, expectedTags?.Select(x => (Byte)x).ToArray());
504+
moveAndExpectTypes(MoveNextSibling, expectedTags.Select(x => (Byte)x).ToArray());
505505
}
506506
/// <summary>
507507
/// Moves to a specified start offset.

Asn1Parser/Asn1Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static Int64 CalculatePayloadLength(Byte[] asnHeader) {
7777
/// <param name="enclosingTag">An enumeration of <see cref="Asn1Type"/> type represented as byte.</param>
7878
/// <returns>Wrapped encoded byte array.</returns>
7979
/// <remarks>If <strong>rawData</strong> is null, an empty tag is encoded.</remarks>
80-
public static Byte[] Encode(Byte[] rawData, Byte enclosingTag) {
80+
public static Byte[] Encode(Byte[]? rawData, Byte enclosingTag) {
8181
if (rawData == null) {
8282
return [enclosingTag, 0];
8383
}

Asn1Parser/AsnFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static Byte[] StringToBinary(String input, EncodingType encoding = Encodi
160160
/// Resolved input string format. If format cannot be determined, <string>Binary</string> type is returned.
161161
/// </returns>
162162
public static EncodingType TestInputString(String input) {
163-
Byte[] rawBytes;
163+
Byte[]? rawBytes;
164164
foreach (PemHeader pemHeader in PemHeader.GetPemHeaders()) {
165165
rawBytes = StringToBinaryFormatter.FromBase64Header(input, pemHeader.GetHeader(), pemHeader.GetFooter());
166166
if (rawBytes != null) {

Asn1Parser/StringToBinaryFormatter.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ namespace SysadminsLV.Asn1Parser;
66
static 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) ??

Asn1Parser/Universal/Asn1BitString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Asn1BitString(Byte[] valueToEncode, Byte unusedBits) : base(TYPE) {
6262
/// <summary>
6363
/// Gets raw value of BIT_STRING without unused bits identifier.
6464
/// </summary>
65-
public Byte[] Value { get; private set; }
65+
public Byte[] Value { get; private set; } = [];
6666

6767
void m_encode(Byte[] value, Boolean calc, Byte unusedBits) {
6868
Value = value;

Asn1Parser/Universal/Asn1Boolean.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public Asn1Boolean(Boolean fValue) : base(TYPE) {
4242
void m_encode(Boolean fValue) {
4343
Value = fValue;
4444
Byte value = (Byte)(fValue ? 255 : 0);
45-
Initialize(new Asn1Reader(Asn1Utils.Encode(new[] {value}, TYPE)));
45+
Initialize(new Asn1Reader(Asn1Utils.Encode([value], TYPE)));
4646
}
4747
void m_decode(Asn1Reader asn) {
48-
Value = asn.GetPayload()[0] > 0;
48+
Value = asn[asn.PayloadStartOffset] > 0;
4949
}
5050
}

Asn1Parser/Universal/Asn1DateTime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public override String GetDisplayValue() {
9191
/// </remarks>
9292
/// <seealso cref="Asn1UtcTime"/>
9393
/// <seealso cref="Asn1GeneralizedTime"/>
94-
public static Asn1DateTime CreateRfcDateTime(DateTime time, TimeZoneInfo zone = null) {
94+
public static Asn1DateTime CreateRfcDateTime(DateTime time, TimeZoneInfo? zone = null) {
9595
if (time.Year is < 2050 and >= 1950) {
9696
return new Asn1UtcTime(time, zone);
9797
}

Asn1Parser/Universal/Asn1ObjectIdentifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Asn1ObjectIdentifier(Oid oid) : base(TYPE) {
5959
/// <summary>
6060
/// Gets value associated with the current object.
6161
/// </summary>
62-
public Oid Value { get; private set; }
62+
public Oid Value { get; private set; } = new();
6363

6464
void m_encode(Oid oid) {
6565
if (String.IsNullOrWhiteSpace(oid.Value)) {

Asn1Parser/Universal/Asn1String.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected Asn1String(Asn1Reader asn, Asn1Type? type) : base(asn, type) { }
4444
/// <summary>
4545
/// Gets value associated with the current object.
4646
/// </summary>
47-
public String Value { get; protected set; }
47+
public String Value { get; protected set; } = String.Empty;
4848

4949
/// <summary>
5050
/// Decodes any ASN.1-encoded binary string into ASN.1 string type instance.
@@ -61,7 +61,7 @@ protected Asn1String(Asn1Reader asn, Asn1Type? type) : base(asn, type) { }
6161
/// <exception cref="Asn1InvalidTagException">
6262
/// Input data is not valid string type.
6363
/// </exception>
64-
public static Asn1String DecodeAnyString(Byte[] rawData, IEnumerable<Asn1Type> allowedStringTypes = null) {
64+
public static Asn1String DecodeAnyString(Byte[] rawData, IEnumerable<Asn1Type>? allowedStringTypes = null) {
6565
if (rawData == null) {
6666
throw new ArgumentNullException(nameof(rawData));
6767
}

0 commit comments

Comments
 (0)