# ASN.1 for Ruby

**URL:** <https://rubytalk.org/t/asn-1-for-ruby/28736>\
**Category:** ruby-talk\
**Created:** [7 July 2006 16:33 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736 "2006-07-07T16:33:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [7 July 2006 16:33 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/1 "2006-07-07T16:33:43Z")

</div>

ASN.1 is one of those binary formats that grew out of ISO. It's lack  
of popularity can perhaps be attributed to the lack of popularity for  
other ISO things like X.400 (ISO MOTIS) mail.  
\<\<\<\<\<\<\<\<\<\<\<

Is anyone actually interested in ASN.1 support for Ruby? I implemented  
enough of it for LDAP in the Net::LDAP library, in a reasonably encapsulated  
way so it could be abstracted into its own package. I'd be happy to do this  
if anyone has a use for it.

> **···**
>
> On another thread ("Grails"), Tor Iver Wilhelmsen \<jadedgamer@hotmail.com\> wrote:
> 
> > [M] Built-in support for ASN.1 would be nice as well. Admittedly,  
> > ASN.1 has apparently been relegated to "just for SNMP traps",  
> > despite the fact that ASN.1 can in theory replace RMI entirely, much  
> > like SOAP. Watch this space.

---

<div class="post-metadata">

**Author:** ![Andrew\_Hodgkinson](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Andrew\_Hodgkinson](https://rubytalk.org/u/Andrew_Hodgkinson)\
**Post date:** [7 July 2006 18:40 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/2 "2006-07-07T18:40:36Z")

</div>

Francis Cianfrocca wrote:

> Is anyone actually interested in ASN.1 support for Ruby? I implemented  
> enough of it for LDAP in the Net::LDAP library, in a reasonably  
> encapsulated way so it could be abstracted into its own package. I'd  
> be happy to do this if anyone has a use for it.

OpenSSL comes with an awful lot of ASN.1 code, though I don't know how  
extensive this is compared to your requirements or your implementation.  
Extracting the ASN.1 part of your LDAP library sounds reasonable.  
However, would it be worth instead (or also) extending the Ruby  
interface to OpenSSL to expose its ASN.1 features?

Sadly documentation on both sides of the fence is pretty poor which  
might not help. Ruby OpenSSL doesn't have much at all; as a starting  
point see:

&nbsp;&nbsp;[http://raa.ruby-lang.org/project/openssl/](http://raa.ruby-lang.org/project/openssl/)

That said there are people using it. It seems to give straightforward  
code from the little bits that I've seen used so far, such as here:

&nbsp;&nbsp;[http://technoweenie.stikipad.com/plugins/show/Reversible+Encrypted+Passwords](http://technoweenie.stikipad.com/plugins/show/Reversible+Encrypted+Passwords)

Although a lot of the crypto library is now documented, the OpenSSL  
project hasn't described the ASN.1 API yet:

&nbsp;&nbsp;[http://www.openssl.org/docs/crypto/crypto.html](http://www.openssl.org/docs/crypto/crypto.html)

The distribution does come with a few relevant .pod files that don't  
seem to be online but they only cover a tiny fraction of the interface  
visible in \<crypto/asn1/asn1.h\>. Meanwhile, Google returns nothing but  
security advisories for "openssl 'asn.1'"... Is it me, or have I just  
spent the last few minutes arguing against myself? 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv1](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@JONNALAGADDA\_Sriniv1](https://rubytalk.org/u/JONNALAGADDA_Sriniv1)\
**Post date:** [8 July 2006 06:26 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/3 "2006-07-08T06:26:42Z")

</div>

Francis Cianfrocca wrote:

> ASN.1 is one of those binary formats that grew out of ISO. It's lack  
> of popularity can perhaps be attributed to the lack of popularity for  
> other ISO things like X.400 (ISO MOTIS) mail.

JS: Several of the biological and chemical databases compiled by NCBI  
&nbsp;&nbsp;&nbsp;&nbsp;use ASN.1 format. For backward compatibility, they also provide flat  
&nbsp;&nbsp;&nbsp;&nbsp;files. However, for newer software, ASN.1 format is recommended.

> Is anyone actually interested in ASN.1 support for Ruby? I implemented  
> enough of it for LDAP in the Net::LDAP library, in a reasonably  
> encapsulated  
> way so it could be abstracted into its own package. I'd be happy to do this  
> if anyone has a use for it.

JS: It would be great to have a Ruby library to parse and search such  
&nbsp;&nbsp;&nbsp;&nbsp;biological and chemical databases in ASN.1 format. For now, since I  
&nbsp;&nbsp;&nbsp;&nbsp;do not have the time to develop one, I am using their flat file  
&nbsp;&nbsp;&nbsp;&nbsp;format.

You could take a look at  
[http://www.ncbi.nih.gov/Sitemap/samplerecord.html](http://www.ncbi.nih.gov/Sitemap/samplerecord.html) to see a sample of the  
data in flat format.

Please send an e-mail to me offline, should you feel that you could  
extract and complete your library.

Best regards,

JS

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [7 July 2006 18:54 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/4 "2006-07-07T18:54:50Z")

</div>

The SSL/TLS wire protocol is a binary format, but it's not based on ASN.1.  
You may be thinking of the X.509 and PKCS standards, which are full of  
ASN.1stuff (and of course they're implemented in the crypto libraries  
that come  
with OpenSSL). For all those applications, I'd say the less the users know  
about the data-representation, the better.

I was wondering about plain old ASN.1 with BER/DER/CER as a transport  
protocol. My guess is that it's not very interesting these days.

> **···**
>
> On 7/7/06, Andrew Hodgkinson \<ahodgkin@rowing.org.uk\> wrote:
> 
> > Francis Cianfrocca wrote:
> > 
> > \> Is anyone actually interested in ASN.1 support for Ruby? I implemented  
> > \> enough of it for LDAP in the Net::LDAP library, in a reasonably  
> > \> encapsulated way so it could be abstracted into its own package. I'd  
> > \> be happy to do this if anyone has a use for it.
> > 
> > OpenSSL comes with an awful lot of ASN.1 code, though I don't know how  
> > extensive this is compared to your requirements or your implementation.  
> > Extracting the ASN.1 part of your LDAP library sounds reasonable.  
> > However, would it be worth instead (or also) extending the Ruby  
> > interface to OpenSSL to expose its ASN.1 features?
> > 
> > Sadly documentation on both sides of the fence is pretty poor which  
> > might not help. Ruby OpenSSL doesn't have much at all; as a starting  
> > point see:
> > 
> > &nbsp;&nbsp;[http://raa.ruby-lang.org/project/openssl/](http://raa.ruby-lang.org/project/openssl/)
> > 
> > That said there are people using it. It seems to give straightforward  
> > code from the little bits that I've seen used so far, such as here:
> > 
> > [http://technoweenie.stikipad.com/plugins/show/Reversible+Encrypted+Passwords](http://technoweenie.stikipad.com/plugins/show/Reversible+Encrypted+Passwords)
> > 
> > Although a lot of the crypto library is now documented, the OpenSSL  
> > project hasn't described the ASN.1 API yet:
> > 
> > &nbsp;&nbsp;[http://www.openssl.org/docs/crypto/crypto.html](http://www.openssl.org/docs/crypto/crypto.html)
> > 
> > The distribution does come with a few relevant .pod files that don't  
> > seem to be online but they only cover a tiny fraction of the interface  
> > visible in \<crypto/asn1/asn1.h\>. Meanwhile, Google returns nothing but  
> > security advisories for "openssl 'asn.1'"... Is it me, or have I just  
> > spent the last few minutes arguing against myself? 🙂
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Tim\_Bray](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@Tim\_Bray](https://rubytalk.org/u/Tim_Bray)\
**Post date:** [8 July 2006 15:14 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/5 "2006-07-08T15:14:15Z")

</div>

People who offer data like this usually regret it when they discover how few ASN.1 tools there are. I've \*never\* found a decently-performing free general-purpose ASN.1 reader; there are a few that you can find, but they're typically buggy, slow, and usually fail on the dataset that you're interested in. -Tim

> **···**
>
> On Jul 7, 2006, at 11:26 PM, Srinivas JONNALAGADDA wrote:
> 
> > JS: Several of the biological and chemical databases compiled by NCBI  
> > &nbsp;&nbsp;&nbsp;&nbsp;use ASN.1 format. For backward compatibility, they also provide flat  
> > &nbsp;&nbsp;&nbsp;&nbsp;files. However, for newer software, ASN.1 format is recommended.

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [8 July 2006 19:11 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/6 "2006-07-08T19:11:44Z")

</div>

The thing about ASN.1 is that it's not a grammar. It's actually a  
grammar-grammar, so it always makes use of an context-specific data  
definition for each domain. Has NCBI published one for theirs?

> **···**
>
> On 7/8/06, Srinivas JONNALAGADDA \<srinivas.j@siritech.com\> wrote:
> 
> > Francis Cianfrocca wrote:  
> > \> ASN.1 is one of those binary formats that grew out of ISO. It's lack  
> > \> of popularity can perhaps be attributed to the lack of popularity for  
> > \> other ISO things like X.400 (ISO MOTIS) mail.
> > 
> > JS: Several of the biological and chemical databases compiled by NCBI  
> > &nbsp;&nbsp;&nbsp;&nbsp;use ASN.1 format. For backward compatibility, they also provide flat  
> > &nbsp;&nbsp;&nbsp;&nbsp;files. However, for newer software, ASN.1 format is recommended.
> > 
> > \> Is anyone actually interested in ASN.1 support for Ruby? I implemented  
> > \> enough of it for LDAP in the Net::LDAP library, in a reasonably  
> > \> encapsulated  
> > \> way so it could be abstracted into its own package. I'd be happy to do  
> > this  
> > \> if anyone has a use for it.
> > 
> > JS: It would be great to have a Ruby library to parse and search such  
> > &nbsp;&nbsp;&nbsp;&nbsp;biological and chemical databases in ASN.1 format. For now, since I  
> > &nbsp;&nbsp;&nbsp;&nbsp;do not have the time to develop one, I am using their flat file  
> > &nbsp;&nbsp;&nbsp;&nbsp;format.
> > 
> > You could take a look at  
> > [http://www.ncbi.nih.gov/Sitemap/samplerecord.html](http://www.ncbi.nih.gov/Sitemap/samplerecord.html) to see a sample of the  
> > data in flat format.
> > 
> > Please send an e-mail to me offline, should you feel that you could  
> > extract and complete your library.
> > 
> > Best regards,
> > 
> > JS

---

<div class="post-metadata">

**Author:** ![Andrew\_Hodgkinson](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Andrew\_Hodgkinson](https://rubytalk.org/u/Andrew_Hodgkinson)\
**Post date:** [7 July 2006 19:25 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/7 "2006-07-07T19:25:02Z")

</div>

Francis Cianfrocca wrote:

> You may be thinking of the X.509 and PKCS standards, which are full of  
> ASN.1stuff (and of course they're implemented in the crypto libraries  
> that come with OpenSSL). For all those applications, I'd say the less  
> the users know about the data-representation, the better.

Yes, I was thinking of this ASN.1 code. The crypto library is highly  
modular; it includes what looks like a generic ASN.1 support library.  
The X.509 etc. code calls into it, but although the asn1.h public header  
file does contain some items that are specfic to OpenSSL operations, it  
gives the impression that it could be used for a much wider range of  
applications. Of course, I could be wrong. I've uploaded the header from  
openssl-0.9.8b at the URL below in case you're interested, to save you  
having to get the whole tarball just for that one file:

&nbsp;&nbsp;[http://pond.org.uk/misc/asn1.h](http://pond.org.uk/misc/asn1.h)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv1](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@JONNALAGADDA\_Sriniv1](https://rubytalk.org/u/JONNALAGADDA_Sriniv1)\
**Post date:** [9 July 2006 04:04 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/8 "2006-07-09T04:04:54Z")

</div>

Tim Bray wrote:

> > JS: Several of the biological and chemical databases compiled by NCBI  
> > &nbsp;&nbsp;&nbsp;&nbsp;use ASN.1 format. For backward compatibility, they also provide flat  
> > &nbsp;&nbsp;&nbsp;&nbsp;files. However, for newer software, ASN.1 format is recommended.
> 
> People who offer data like this usually regret it when they discover how  
> few ASN.1 tools there are. I've \*never\* found a decently-performing free  
> general-purpose ASN.1 reader; there are a few that you can find, but  
> they're typically buggy, slow, and usually fail on the dataset that  
> you're interested in. -Tim

That is probably why NCBI, in this case, also provides a set of tools to  
deal with their data.

However, if I could quickly write a few lines of Ruby to parse some data  
in my own way, I would rather avoid doing that in C. And that is how I  
was asking Francis about a Ruby ASN.1 library.

Best regards,

JS

> **···**
>
> > On Jul 7, 2006, at 11:26 PM, Srinivas JONNALAGADDA wrote:

---

<div class="post-metadata">

**Author:** ![Daniel\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@Daniel\_Martin](https://rubytalk.org/u/Daniel_Martin)\
**Post date:** [11 July 2006 14:23 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/9 "2006-07-11T14:23:21Z")

</div>

"Francis Cianfrocca" \<garbagecat10@gmail.com\> writes:

> The thing about ASN.1 is that it's not a grammar. It's actually a  
> grammar-grammar, so it always makes use of an context-specific data  
> definition for each domain. Has NCBI published one for theirs?

There are a whole load of \*.asn files (in ASN.1 format) inside  
ftp://ftp.ncbi.nih.gov/toolbox/ncbi\_tools/CURRENT/ncbi.tar.gz

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [7 July 2006 20:06 UTC](https://rubytalk.org/t/asn-1-for-ruby/28736/10 "2006-07-07T20:06:20Z")

</div>

Thanks for sending the library, Andrew, but as it turns out I'm already  
quite familiar with the inside of OpenSSL ;-). Part of the point of doing  
the Net::LDAP library (and an eventual Net::ASN1 library should there be a  
need for it) is to have everything be in pure Ruby.

> **···**
>
> On 7/7/06, Andrew Hodgkinson \<ahodgkin@rowing.org.uk\> wrote:
> 
> > Francis Cianfrocca wrote:
> > 
> > \> You may be thinking of the X.509 and PKCS standards, which are full of  
> > \> ASN.1stuff (and of course they're implemented in the crypto libraries  
> > \> that come with OpenSSL). For all those applications, I'd say the less  
> > \> the users know about the data-representation, the better.
> > 
> > Yes, I was thinking of this ASN.1 code. The crypto library is highly  
> > modular; it includes what looks like a generic ASN.1 support library.  
> > The X.509 etc. code calls into it, but although the asn1.h public header  
> > file does contain some items that are specfic to OpenSSL operations, it  
> > gives the impression that it could be used for a much wider range of  
> > applications. Of course, I could be wrong. I've uploaded the header from  
> > openssl-0.9.8b at the URL below in case you're interested, to save you  
> > having to get the whole tarball just for that one file:
> > 
> > &nbsp;&nbsp;[http://pond.org.uk/misc/asn1.h](http://pond.org.uk/misc/asn1.h)
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
