@@ -345,129 +345,6 @@ Init_ossl_asn1(void)
345345 sivINDEFINITE_LENGTH = rb_intern ("@indefinite_length" );
346346 sivUNUSED_BITS = rb_intern ("@unused_bits" );
347347
348- /*
349- * Document-module: OpenSSL::ASN1
350- *
351- * Abstract Syntax Notation One (or ASN.1) is a notation syntax to
352- * describe data structures and is defined in ITU-T X.680. ASN.1 itself
353- * does not mandate any encoding or parsing rules, but usually ASN.1 data
354- * structures are encoded using the Distinguished Encoding Rules (DER) or
355- * less often the Basic Encoding Rules (BER) described in ITU-T X.690. DER
356- * and BER encodings are binary Tag-Length-Value (TLV) encodings that are
357- * quite concise compared to other popular data description formats such
358- * as XML, JSON etc.
359- * ASN.1 data structures are very common in cryptographic applications,
360- * e.g. X.509 public key certificates or certificate revocation lists
361- * (CRLs) are all defined in ASN.1 and DER-encoded. ASN.1, DER and BER are
362- * the building blocks of applied cryptography.
363- * The ASN1 module provides the necessary classes that allow generation
364- * of ASN.1 data structures and the methods to encode them using a DER
365- * encoding. The decode method allows parsing arbitrary BER-/DER-encoded
366- * data to a Ruby object that can then be modified and re-encoded at will.
367- *
368- * == ASN.1 class hierarchy
369- *
370- * The base class representing ASN.1 structures is ASN1Data. ASN1Data offers
371- * attributes to read and set the _tag_, the _tag_class_ and finally the
372- * _value_ of a particular ASN.1 item. Upon parsing, any tagged values
373- * (implicit or explicit) will be represented by ASN1Data instances because
374- * their "real type" can only be determined using out-of-band information
375- * from the ASN.1 type declaration. Since this information is normally
376- * known when encoding a type, all sub-classes of ASN1Data offer an
377- * additional attribute _tagging_ that allows to encode a value implicitly
378- * (+:IMPLICIT+) or explicitly (+:EXPLICIT+).
379- *
380- * === Constructive
381- *
382- * Constructive is, as its name implies, the base class for all
383- * constructed encodings, i.e. those that consist of several values,
384- * opposed to "primitive" encodings with just one single value. The value of
385- * an Constructive is always an Array.
386- *
387- * ==== ASN1::Set and ASN1::Sequence
388- *
389- * The most common constructive encodings are SETs and SEQUENCEs, which is
390- * why there are two sub-classes of Constructive representing each of
391- * them.
392- *
393- * === Primitive
394- *
395- * This is the super class of all primitive values. Primitive
396- * itself is not used when parsing ASN.1 data, all values are either
397- * instances of a corresponding sub-class of Primitive or they are
398- * instances of ASN1Data if the value was tagged implicitly or explicitly.
399- * Please cf. Primitive documentation for details on sub-classes and
400- * their respective mappings of ASN.1 data types to Ruby objects.
401- *
402- * == Possible values for _tagging_
403- *
404- * When constructing an ASN1Data object the ASN.1 type definition may
405- * require certain elements to be either implicitly or explicitly tagged.
406- * This can be achieved by setting the _tagging_ attribute manually for
407- * sub-classes of ASN1Data. Use the symbol +:IMPLICIT+ for implicit
408- * tagging and +:EXPLICIT+ if the element requires explicit tagging.
409- *
410- * == Possible values for _tag_class_
411- *
412- * It is possible to create arbitrary ASN1Data objects that also support
413- * a PRIVATE or APPLICATION tag class. Possible values for the _tag_class_
414- * attribute are:
415- * * +:UNIVERSAL+ (the default for untagged values)
416- * * +:CONTEXT_SPECIFIC+ (the default for tagged values)
417- * * +:APPLICATION+
418- * * +:PRIVATE+
419- *
420- * == Tag constants
421- *
422- * There is a constant defined for each universal tag:
423- * * OpenSSL::ASN1::EOC (0)
424- * * OpenSSL::ASN1::BOOLEAN (1)
425- * * OpenSSL::ASN1::INTEGER (2)
426- * * OpenSSL::ASN1::BIT_STRING (3)
427- * * OpenSSL::ASN1::OCTET_STRING (4)
428- * * OpenSSL::ASN1::NULL (5)
429- * * OpenSSL::ASN1::OBJECT (6)
430- * * OpenSSL::ASN1::ENUMERATED (10)
431- * * OpenSSL::ASN1::UTF8STRING (12)
432- * * OpenSSL::ASN1::SEQUENCE (16)
433- * * OpenSSL::ASN1::SET (17)
434- * * OpenSSL::ASN1::NUMERICSTRING (18)
435- * * OpenSSL::ASN1::PRINTABLESTRING (19)
436- * * OpenSSL::ASN1::T61STRING (20)
437- * * OpenSSL::ASN1::VIDEOTEXSTRING (21)
438- * * OpenSSL::ASN1::IA5STRING (22)
439- * * OpenSSL::ASN1::UTCTIME (23)
440- * * OpenSSL::ASN1::GENERALIZEDTIME (24)
441- * * OpenSSL::ASN1::GRAPHICSTRING (25)
442- * * OpenSSL::ASN1::ISO64STRING (26)
443- * * OpenSSL::ASN1::GENERALSTRING (27)
444- * * OpenSSL::ASN1::UNIVERSALSTRING (28)
445- * * OpenSSL::ASN1::BMPSTRING (30)
446- *
447- * == UNIVERSAL_TAG_NAME constant
448- *
449- * An Array that stores the name of a given tag number. These names are
450- * the same as the name of the tag constant that is additionally defined,
451- * e.g. <tt>UNIVERSAL_TAG_NAME[2] = "INTEGER"</tt> and <tt>OpenSSL::ASN1::INTEGER = 2</tt>.
452- *
453- * == Example usage
454- *
455- * === Decoding and viewing a DER-encoded file
456- * require 'openssl'
457- * require 'pp'
458- * der = File.binread('data.der')
459- * asn1 = OpenSSL::ASN1.decode(der)
460- * pp der
461- *
462- * === Creating an ASN.1 structure and DER-encoding it
463- * require 'openssl'
464- * version = OpenSSL::ASN1::Integer.new(1)
465- * # Explicitly 0-tagged implies context-specific tag class
466- * serial = OpenSSL::ASN1::Integer.new(12345, 0, :EXPLICIT, :CONTEXT_SPECIFIC)
467- * name = OpenSSL::ASN1::PrintableString.new('Data 1')
468- * sequence = OpenSSL::ASN1::Sequence.new( [ version, serial, name ] )
469- * der = sequence.to_der
470- */
471348 mASN1 = rb_define_module_under (mOSSL , "ASN1" );
472349
473350 /* Document-class: OpenSSL::ASN1::ASN1Error
@@ -488,190 +365,11 @@ Init_ossl_asn1(void)
488365 rb_ary_store (ary , i , rb_str_new2 (ossl_asn1_info [i ].name ));
489366 }
490367
491- /* Document-class: OpenSSL::ASN1::ASN1Data
492- *
493- * The top-level class representing any ASN.1 object. When parsed by
494- * ASN1.decode, tagged values are always represented by an instance
495- * of ASN1Data.
496- *
497- * == The role of ASN1Data for parsing tagged values
498- *
499- * When encoding an ASN.1 type it is inherently clear what original
500- * type (e.g. INTEGER, OCTET STRING etc.) this value has, regardless
501- * of its tagging.
502- * But opposed to the time an ASN.1 type is to be encoded, when parsing
503- * them it is not possible to deduce the "real type" of tagged
504- * values. This is why tagged values are generally parsed into ASN1Data
505- * instances, but with a different outcome for implicit and explicit
506- * tagging.
507- *
508- * === Example of a parsed implicitly tagged value
509- *
510- * An implicitly 1-tagged INTEGER value will be parsed as an
511- * ASN1Data with
512- * * _tag_ equal to 1
513- * * _tag_class_ equal to +:CONTEXT_SPECIFIC+
514- * * _value_ equal to a String that carries the raw encoding
515- * of the INTEGER.
516- * This implies that a subsequent decoding step is required to
517- * completely decode implicitly tagged values.
518- *
519- * === Example of a parsed explicitly tagged value
520- *
521- * An explicitly 1-tagged INTEGER value will be parsed as an
522- * ASN1Data with
523- * * _tag_ equal to 1
524- * * _tag_class_ equal to +:CONTEXT_SPECIFIC+
525- * * _value_ equal to an Array with one single element, an
526- * instance of OpenSSL::ASN1::Integer, i.e. the inner element
527- * is the non-tagged primitive value, and the tagging is represented
528- * in the outer ASN1Data
529- *
530- * == Example - Decoding an implicitly tagged INTEGER
531- * int = OpenSSL::ASN1::Integer.new(1, 0, :IMPLICIT) # implicit 0-tagged
532- * seq = OpenSSL::ASN1::Sequence.new( [int] )
533- * der = seq.to_der
534- * asn1 = OpenSSL::ASN1.decode(der)
535- * # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0
536- * # @indefinite_length=false,
537- * # @tag=16,
538- * # @tag_class=:UNIVERSAL,
539- * # @tagging=nil,
540- * # @value=
541- * # [#<OpenSSL::ASN1::ASN1Data:0x87326f4
542- * # @indefinite_length=false,
543- * # @tag=0,
544- * # @tag_class=:CONTEXT_SPECIFIC,
545- * # @value="\x01">]>
546- * raw_int = asn1.value[0]
547- * # manually rewrite tag and tag class to make it an UNIVERSAL value
548- * raw_int.tag = OpenSSL::ASN1::INTEGER
549- * raw_int.tag_class = :UNIVERSAL
550- * int2 = OpenSSL::ASN1.decode(raw_int)
551- * puts int2.value # => 1
552- *
553- * == Example - Decoding an explicitly tagged INTEGER
554- * int = OpenSSL::ASN1::Integer.new(1, 0, :EXPLICIT) # explicit 0-tagged
555- * seq = OpenSSL::ASN1::Sequence.new( [int] )
556- * der = seq.to_der
557- * asn1 = OpenSSL::ASN1.decode(der)
558- * # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0
559- * # @indefinite_length=false,
560- * # @tag=16,
561- * # @tag_class=:UNIVERSAL,
562- * # @tagging=nil,
563- * # @value=
564- * # [#<OpenSSL::ASN1::ASN1Data:0x87326f4
565- * # @indefinite_length=false,
566- * # @tag=0,
567- * # @tag_class=:CONTEXT_SPECIFIC,
568- * # @value=
569- * # [#<OpenSSL::ASN1::Integer:0x85bf308
570- * # @indefinite_length=false,
571- * # @tag=2,
572- * # @tag_class=:UNIVERSAL
573- * # @tagging=nil,
574- * # @value=1>]>]>
575- * int2 = asn1.value[0].value[0]
576- * puts int2.value # => 1
577- */
578- cASN1Data = rb_define_class_under (mASN1 , "ASN1Data" , rb_cObject );
579368
580- /* Document-class: OpenSSL::ASN1::Primitive
581- *
582- * The parent class for all primitive encodings. Attributes are the same as
583- * for ASN1Data, with the addition of _tagging_.
584- * Primitive values can never be encoded with indefinite length form, thus
585- * it is not possible to set the _indefinite_length_ attribute for Primitive
586- * and its sub-classes.
587- *
588- * == Primitive sub-classes and their mapping to Ruby classes
589- * * OpenSSL::ASN1::EndOfContent <=> _value_ is always +nil+
590- * * OpenSSL::ASN1::Boolean <=> _value_ is +true+ or +false+
591- * * OpenSSL::ASN1::Integer <=> _value_ is an OpenSSL::BN
592- * * OpenSSL::ASN1::BitString <=> _value_ is a String
593- * * OpenSSL::ASN1::OctetString <=> _value_ is a String
594- * * OpenSSL::ASN1::Null <=> _value_ is always +nil+
595- * * OpenSSL::ASN1::Object <=> _value_ is a String
596- * * OpenSSL::ASN1::Enumerated <=> _value_ is an OpenSSL::BN
597- * * OpenSSL::ASN1::UTF8String <=> _value_ is a String
598- * * OpenSSL::ASN1::NumericString <=> _value_ is a String
599- * * OpenSSL::ASN1::PrintableString <=> _value_ is a String
600- * * OpenSSL::ASN1::T61String <=> _value_ is a String
601- * * OpenSSL::ASN1::VideotexString <=> _value_ is a String
602- * * OpenSSL::ASN1::IA5String <=> _value_ is a String
603- * * OpenSSL::ASN1::UTCTime <=> _value_ is a Time
604- * * OpenSSL::ASN1::GeneralizedTime <=> _value_ is a Time
605- * * OpenSSL::ASN1::GraphicString <=> _value_ is a String
606- * * OpenSSL::ASN1::ISO64String <=> _value_ is a String
607- * * OpenSSL::ASN1::GeneralString <=> _value_ is a String
608- * * OpenSSL::ASN1::UniversalString <=> _value_ is a String
609- * * OpenSSL::ASN1::BMPString <=> _value_ is a String
610- *
611- * == OpenSSL::ASN1::BitString
612- *
613- * === Additional attributes
614- * _unused_bits_: if the underlying BIT STRING's
615- * length is a multiple of 8 then _unused_bits_ is 0. Otherwise
616- * _unused_bits_ indicates the number of bits that are to be ignored in
617- * the final octet of the BitString's _value_.
618- *
619- * == OpenSSL::ASN1::ObjectId
620- *
621- * NOTE: While OpenSSL::ASN1::ObjectId.new will allocate a new ObjectId,
622- * it is not typically allocated this way, but rather that are received from
623- * parsed ASN1 encodings.
624- *
625- * === Additional attributes
626- * * _sn_: the short name as defined in <openssl/objects.h>.
627- * * _ln_: the long name as defined in <openssl/objects.h>.
628- * * _oid_: the object identifier as a String, e.g. "1.2.3.4.5"
629- * * _short_name_: alias for _sn_.
630- * * _long_name_: alias for _ln_.
631- *
632- * == Examples
633- * With the Exception of OpenSSL::ASN1::EndOfContent, each Primitive class
634- * constructor takes at least one parameter, the _value_.
635- *
636- * === Creating EndOfContent
637- * eoc = OpenSSL::ASN1::EndOfContent.new
638- *
639- * === Creating any other Primitive
640- * prim = <class>.new(value) # <class> being one of the sub-classes except EndOfContent
641- * prim_zero_tagged_implicit = <class>.new(value, 0, :IMPLICIT)
642- * prim_zero_tagged_explicit = <class>.new(value, 0, :EXPLICIT)
643- */
369+ cASN1Data = rb_define_class_under (mASN1 , "ASN1Data" , rb_cObject );
644370 cASN1Primitive = rb_define_class_under (mASN1 , "Primitive" , cASN1Data );
645371
646- /* Document-class: OpenSSL::ASN1::Constructive
647- *
648- * The parent class for all constructed encodings. The _value_ attribute
649- * of a Constructive is always an Array. Attributes are the same as
650- * for ASN1Data, with the addition of _tagging_.
651- *
652- * == SET and SEQUENCE
653- *
654- * Most constructed encodings come in the form of a SET or a SEQUENCE.
655- * These encodings are represented by one of the two sub-classes of
656- * Constructive:
657- * * OpenSSL::ASN1::Set
658- * * OpenSSL::ASN1::Sequence
659- * Please note that tagged sequences and sets are still parsed as
660- * instances of ASN1Data. Find further details on tagged values
661- * there.
662- *
663- * === Example - constructing a SEQUENCE
664- * int = OpenSSL::ASN1::Integer.new(1)
665- * str = OpenSSL::ASN1::PrintableString.new('abc')
666- * sequence = OpenSSL::ASN1::Sequence.new( [ int, str ] )
667- *
668- * === Example - constructing a SET
669- * int = OpenSSL::ASN1::Integer.new(1)
670- * str = OpenSSL::ASN1::PrintableString.new('abc')
671- * set = OpenSSL::ASN1::Set.new( [ int, str ] )
672- */
673372 cASN1Constructive = rb_define_class_under (mASN1 ,"Constructive" , cASN1Data );
674-
675373#define OSSL_ASN1_DEFINE_CLASS (name , super ) \
676374do{\
677375 cASN1##name = rb_define_class_under(mASN1, #name, cASN1##super);\
@@ -705,10 +403,6 @@ do{\
705403 OSSL_ASN1_DEFINE_CLASS (EndOfContent , Data );
706404
707405
708- /* Document-class: OpenSSL::ASN1::ObjectId
709- *
710- * Represents the primitive object id for OpenSSL::ASN1
711- */
712406#if 0
713407 cASN1ObjectId = rb_define_class_under (mASN1 , "ObjectId" , cASN1Primitive ); /* let rdoc know */
714408#endif
0 commit comments