in src/PFXImportPowershell/EncryptionUtilities/Source/DerUtils.cs [382:436]
public static string DecodeOid(byte[] bytes)
{
StringBuilder oidDotStr = new StringBuilder();
if (bytes == null)
{
throw new ArgumentNullException("bytes");
}
if (bytes.Length < 1)
{
throw new ArgumentException("Input bytes are not valid DER format");
}
if(bytes[0] != TagOid)
{
throw new ArgumentException("Not an OID entry");
}
uint dataLength;
uint lengthBytesUsed;
DecodeLength(bytes, 1, out dataLength, out lengthBytesUsed);
// validate data size
if (bytes.Length != 1 + lengthBytesUsed + dataLength)
{
throw new ArgumentException("Input bytes are not valid DER format");
}
uint position = 1 + lengthBytesUsed;
oidDotStr.Append(bytes[position] / 40).Append(".").Append(bytes[position] % 40);
position++;
while(position < bytes.Length)
{
if(bytes[position] < 0x80)
{
oidDotStr.Append(".").Append(bytes[position]);
position++;
}
else
{
int nodeValue = 0;
while(bytes[position] > 0x80)
{
nodeValue += bytes[position] & 0x7f;
nodeValue <<= 7;
position++;
}
nodeValue += bytes[position];
oidDotStr.Append(".").Append(nodeValue);
position++;
}
}
return oidDotStr.ToString(); ;
}