 | | From: | Robin de Krijger | | Subject: | From hex-notation to ASN.1 notation: how?!? | | Date: | Wed, 19 Jan 2005 16:50:03 +0100 |
|
|
 | I have the following hex string: 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d
Which is equal to the ASN.1 object identifier: 1.2.840.113549
I read this in the documentation. But how does this mapping work?!? How can I calculatie the OID from the hex-string (and vica versa)
Regards, Robin de Krijger
|
|
 | | From: | Bryan Olson | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Wed, 19 Jan 2005 17:12:57 GMT |
|
|
 | Robin de Krijger wrote: > I have the following hex string: > 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d > > Which is equal to the ASN.1 object identifier: > 1.2.840.113549 > > I read this in the documentation. But how does this mapping work?!? > How can I calculatie the OID from the hex-string (and vica versa)
Below is arc_list -> octets in the Python language. The actual BER encoding would also have a tag and length field. If you want to know more, you can download /ASN.1 Complete/ by John Larmouth from:
http://www.oss.com/asn1/larmouth.html
I like Larmouth's book better than the /Layman's Guide/.
--Bryan
def to_base128(n): """ Return a list of bytes holding the big-endian base-128 encoding used for tags > 30 and OID elements after the first two. High bit is set except on last octet. """ # Build it least-significant byte first, then reverse the bytes. bytes = [n & 0x7F] while n > 127: n >>= 7 bytes.append(n & 0x7F | 0x80) bytes.reverse() return bytes
def encode_arc_list(arc_list): """ Encode an OID arc list into the value portion of a BER field. """ # First-octet special encoding of first two arcs bytes = [40 * arc_list[0] + arc_list[1]] # After that, they're base-128 big endian; top bit is continue flag. for arc in arc_list[2:]: bytes.extend(to_base128(arc)) return bytes
print [hex(byte) for byte in encode_arc_list([1, 2, 840, 113549])]
|
|
 | | From: | Robin de Krijger | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Thu, 20 Jan 2005 08:39:50 +0100 |
|
|
 | "Bryan Olson" wrote:
> Below is arc_list -> octets in the Python language. The actual > BER encoding would also have a tag and length field.
Hm, it is not as straightfoward as I thought it would be... :-(
Thanks, I'll study it!
Regards, Robin...
|
|
 | | From: | Bryan Olson | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Thu, 20 Jan 2005 08:56:44 GMT |
|
|
 | Robin de Krijger wrote: > "Bryan Olson" >>Below is arc_list -> octets [...] > > Hm, it is not as straightfoward as I thought it would be... :-(
The only really tricky part is that they encode the first two arcs into the first octet. They assume that there are only a few OIDs at that level (then enforce the assumption by not granting more).
-- --Bryan
|
|
 | | From: | Paul Rubin | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | 19 Jan 2005 08:21:45 -0800 |
|
|
 | "Robin de Krijger" writes: > I read this in the documentation. But how does this mapping work?!? > How can I calculatie the OID from the hex-string (and vica versa)
Google for "Layman's guide to BER" by Burt Kaliski.
|
|
 | | From: | Robin de Krijger | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Thu, 20 Jan 2005 08:38:33 +0100 |
|
|
 | "Paul Rubin" wrote:
> Google for "Layman's guide to BER" by Burt Kaliski.
Thanks, I'll get into it!
Regards, Robin...
|
|
 | | From: | Bruce Stephens | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Wed, 19 Jan 2005 16:14:29 +0000 |
|
|
 | "Robin de Krijger" writes:
[...]
> I read this in the documentation. But how does this mapping work?!? > How can I calculatie the OID from the hex-string (and vica versa)
If you really want to know, "A Layman's Guide to a Subset of ASN.1, BER, and DER" will tell you. It's available all over the place, for example, .
|
|
 | | From: | Robin de Krijger | | Subject: | Re: From hex-notation to ASN.1 notation: how?!? | | Date: | Thu, 20 Jan 2005 08:38:06 +0100 |
|
|
 | "Bruce Stephens" wrote:
[...] > If you really want to know, "A Layman's Guide to a Subset of ASN.1, > BER, and DER" will tell you. It's available all over the place, for > example, .
Thanks, I'll get into it!
Regards, Robin...
|
|