Skip to content

Commit f447c6e

Browse files
committed
updated Asn1ObjectIdentifier to use refactored OID encoder
1 parent ccc7d57 commit f447c6e

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

Asn1Parser/Universal/Asn1ObjectIdentifier.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Numerics;
55
using System.Security.Cryptography;
66
using System.Text;
7+
using SysadminsLV.Asn1Parser.Utils;
78

89
namespace SysadminsLV.Asn1Parser.Universal;
910

@@ -80,7 +81,6 @@ static Byte[] encode(IList<BigInteger> tokens) {
8081
var rawOid = new List<Byte>();
8182
for (Int32 tokenIndex = 0; tokenIndex < tokens.Count; tokenIndex++) {
8283
BigInteger token = tokens[tokenIndex];
83-
BigInteger temp = token;
8484
// first two arcs are encoded as a single arc
8585
switch (tokenIndex) {
8686
case 0:
@@ -94,27 +94,12 @@ static Byte[] encode(IList<BigInteger> tokens) {
9494
}
9595
// otherwise first two arcs are encoded using multiple bytes, and we have to go through
9696
// standard OID arc encoding routine.
97-
temp = token;
9897
break;
9998
// we already handled 2nd arc, so skip its processing.
10099
case 1:
101100
continue;
102101
}
103-
Int16 bitLength = 0;
104-
// calculate how many bits are occupied by the current integer value
105-
do {
106-
temp = (BigInteger)Math.Floor((Double)temp / 2);
107-
bitLength++;
108-
} while (temp > 0);
109-
// calculate how many additional bytes are required and encode each integer in a 7 bit.
110-
// 8th bit of the integer is shifted to the left and 8th bit is set to 1 to indicate that
111-
// additional bytes are related to the current OID arc. Details:
112-
// http://msdn.microsoft.com/en-us/library/bb540809(v=vs.85).aspx
113-
// loop may not execute if arc value is less than 128.
114-
for (Int32 index = (bitLength - 1) / 7; index > 0; index--) {
115-
rawOid.Add((Byte)(0x80 | ((token >> (index * 7)) & 0x7f)));
116-
}
117-
rawOid.Add((Byte)(token & 0x7f));
102+
rawOid.AddRange(OidUtils.EncodeOidArc(token));
118103
}
119104
return rawOid.ToArray();
120105
}

0 commit comments

Comments
 (0)