@@ -401,129 +401,6 @@ Init_ossl_asn1(void)
401401 sivINDEFINITE_LENGTH = rb_intern ("@indefinite_length" );
402402 sivUNUSED_BITS = rb_intern ("@unused_bits" );
403403
404- /*
405- * Document-module: OpenSSL::ASN1
406- *
407- * Abstract Syntax Notation One (or ASN.1) is a notation syntax to
408- * describe data structures and is defined in ITU-T X.680. ASN.1 itself
409- * does not mandate any encoding or parsing rules, but usually ASN.1 data
410- * structures are encoded using the Distinguished Encoding Rules (DER) or
411- * less often the Basic Encoding Rules (BER) described in ITU-T X.690. DER
412- * and BER encodings are binary Tag-Length-Value (TLV) encodings that are
413- * quite concise compared to other popular data description formats such
414- * as XML, JSON etc.
415- * ASN.1 data structures are very common in cryptographic applications,
416- * e.g. X.509 public key certificates or certificate revocation lists
417- * (CRLs) are all defined in ASN.1 and DER-encoded. ASN.1, DER and BER are
418- * the building blocks of applied cryptography.
419- * The ASN1 module provides the necessary classes that allow generation
420- * of ASN.1 data structures and the methods to encode them using a DER
421- * encoding. The decode method allows parsing arbitrary BER-/DER-encoded
422- * data to a Ruby object that can then be modified and re-encoded at will.
423- *
424- * == ASN.1 class hierarchy
425- *
426- * The base class representing ASN.1 structures is ASN1Data. ASN1Data offers
427- * attributes to read and set the _tag_, the _tag_class_ and finally the
428- * _value_ of a particular ASN.1 item. Upon parsing, any tagged values
429- * (implicit or explicit) will be represented by ASN1Data instances because
430- * their "real type" can only be determined using out-of-band information
431- * from the ASN.1 type declaration. Since this information is normally
432- * known when encoding a type, all sub-classes of ASN1Data offer an
433- * additional attribute _tagging_ that allows to encode a value implicitly
434- * (+:IMPLICIT+) or explicitly (+:EXPLICIT+).
435- *
436- * === Constructive
437- *
438- * Constructive is, as its name implies, the base class for all
439- * constructed encodings, i.e. those that consist of several values,
440- * opposed to "primitive" encodings with just one single value. The value of
441- * an Constructive is always an Array.
442- *
443- * ==== ASN1::Set and ASN1::Sequence
444- *
445- * The most common constructive encodings are SETs and SEQUENCEs, which is
446- * why there are two sub-classes of Constructive representing each of
447- * them.
448- *
449- * === Primitive
450- *
451- * This is the super class of all primitive values. Primitive
452- * itself is not used when parsing ASN.1 data, all values are either
453- * instances of a corresponding sub-class of Primitive or they are
454- * instances of ASN1Data if the value was tagged implicitly or explicitly.
455- * Please cf. Primitive documentation for details on sub-classes and
456- * their respective mappings of ASN.1 data types to Ruby objects.
457- *
458- * == Possible values for _tagging_
459- *
460- * When constructing an ASN1Data object the ASN.1 type definition may
461- * require certain elements to be either implicitly or explicitly tagged.
462- * This can be achieved by setting the _tagging_ attribute manually for
463- * sub-classes of ASN1Data. Use the symbol +:IMPLICIT+ for implicit
464- * tagging and +:EXPLICIT+ if the element requires explicit tagging.
465- *
466- * == Possible values for _tag_class_
467- *
468- * It is possible to create arbitrary ASN1Data objects that also support
469- * a PRIVATE or APPLICATION tag class. Possible values for the _tag_class_
470- * attribute are:
471- * * +:UNIVERSAL+ (the default for untagged values)
472- * * +:CONTEXT_SPECIFIC+ (the default for tagged values)
473- * * +:APPLICATION+
474- * * +:PRIVATE+
475- *
476- * == Tag constants
477- *
478- * There is a constant defined for each universal tag:
479- * * OpenSSL::ASN1::EOC (0)
480- * * OpenSSL::ASN1::BOOLEAN (1)
481- * * OpenSSL::ASN1::INTEGER (2)
482- * * OpenSSL::ASN1::BIT_STRING (3)
483- * * OpenSSL::ASN1::OCTET_STRING (4)
484- * * OpenSSL::ASN1::NULL (5)
485- * * OpenSSL::ASN1::OBJECT (6)
486- * * OpenSSL::ASN1::ENUMERATED (10)
487- * * OpenSSL::ASN1::UTF8STRING (12)
488- * * OpenSSL::ASN1::SEQUENCE (16)
489- * * OpenSSL::ASN1::SET (17)
490- * * OpenSSL::ASN1::NUMERICSTRING (18)
491- * * OpenSSL::ASN1::PRINTABLESTRING (19)
492- * * OpenSSL::ASN1::T61STRING (20)
493- * * OpenSSL::ASN1::VIDEOTEXSTRING (21)
494- * * OpenSSL::ASN1::IA5STRING (22)
495- * * OpenSSL::ASN1::UTCTIME (23)
496- * * OpenSSL::ASN1::GENERALIZEDTIME (24)
497- * * OpenSSL::ASN1::GRAPHICSTRING (25)
498- * * OpenSSL::ASN1::ISO64STRING (26)
499- * * OpenSSL::ASN1::GENERALSTRING (27)
500- * * OpenSSL::ASN1::UNIVERSALSTRING (28)
501- * * OpenSSL::ASN1::BMPSTRING (30)
502- *
503- * == UNIVERSAL_TAG_NAME constant
504- *
505- * An Array that stores the name of a given tag number. These names are
506- * the same as the name of the tag constant that is additionally defined,
507- * e.g. <tt>UNIVERSAL_TAG_NAME[2] = "INTEGER"</tt> and <tt>OpenSSL::ASN1::INTEGER = 2</tt>.
508- *
509- * == Example usage
510- *
511- * === Decoding and viewing a DER-encoded file
512- * require 'openssl'
513- * require 'pp'
514- * der = File.binread('data.der')
515- * asn1 = OpenSSL::ASN1.decode(der)
516- * pp der
517- *
518- * === Creating an ASN.1 structure and DER-encoding it
519- * require 'openssl'
520- * version = OpenSSL::ASN1::Integer.new(1)
521- * # Explicitly 0-tagged implies context-specific tag class
522- * serial = OpenSSL::ASN1::Integer.new(12345, 0, :EXPLICIT, :CONTEXT_SPECIFIC)
523- * name = OpenSSL::ASN1::PrintableString.new('Data 1')
524- * sequence = OpenSSL::ASN1::Sequence.new( [ version, serial, name ] )
525- * der = sequence.to_der
526- */
527404 mASN1 = rb_define_module_under (mOSSL , "ASN1" );
528405
529406 /* Document-class: OpenSSL::ASN1::ASN1Error
@@ -544,190 +421,11 @@ Init_ossl_asn1(void)
544421 rb_ary_store (ary , i , rb_str_new2 (ossl_asn1_info [i ].name ));
545422 }
546423
547- /* Document-class: OpenSSL::ASN1::ASN1Data
548- *
549- * The top-level class representing any ASN.1 object. When parsed by
550- * ASN1.decode, tagged values are always represented by an instance
551- * of ASN1Data.
552- *
553- * == The role of ASN1Data for parsing tagged values
554- *
555- * When encoding an ASN.1 type it is inherently clear what original
556- * type (e.g. INTEGER, OCTET STRING etc.) this value has, regardless
557- * of its tagging.
558- * But opposed to the time an ASN.1 type is to be encoded, when parsing
559- * them it is not possible to deduce the "real type" of tagged
560- * values. This is why tagged values are generally parsed into ASN1Data
561- * instances, but with a different outcome for implicit and explicit
562- * tagging.
563- *
564- * === Example of a parsed implicitly tagged value
565- *
566- * An implicitly 1-tagged INTEGER value will be parsed as an
567- * ASN1Data with
568- * * _tag_ equal to 1
569- * * _tag_class_ equal to +:CONTEXT_SPECIFIC+
570- * * _value_ equal to a String that carries the raw encoding
571- * of the INTEGER.
572- * This implies that a subsequent decoding step is required to
573- * completely decode implicitly tagged values.
574- *
575- * === Example of a parsed explicitly tagged value
576- *
577- * An explicitly 1-tagged INTEGER value will be parsed as an
578- * ASN1Data with
579- * * _tag_ equal to 1
580- * * _tag_class_ equal to +:CONTEXT_SPECIFIC+
581- * * _value_ equal to an Array with one single element, an
582- * instance of OpenSSL::ASN1::Integer, i.e. the inner element
583- * is the non-tagged primitive value, and the tagging is represented
584- * in the outer ASN1Data
585- *
586- * == Example - Decoding an implicitly tagged INTEGER
587- * int = OpenSSL::ASN1::Integer.new(1, 0, :IMPLICIT) # implicit 0-tagged
588- * seq = OpenSSL::ASN1::Sequence.new( [int] )
589- * der = seq.to_der
590- * asn1 = OpenSSL::ASN1.decode(der)
591- * # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0
592- * # @indefinite_length=false,
593- * # @tag=16,
594- * # @tag_class=:UNIVERSAL,
595- * # @tagging=nil,
596- * # @value=
597- * # [#<OpenSSL::ASN1::ASN1Data:0x87326f4
598- * # @indefinite_length=false,
599- * # @tag=0,
600- * # @tag_class=:CONTEXT_SPECIFIC,
601- * # @value="\x01">]>
602- * raw_int = asn1.value[0]
603- * # manually rewrite tag and tag class to make it an UNIVERSAL value
604- * raw_int.tag = OpenSSL::ASN1::INTEGER
605- * raw_int.tag_class = :UNIVERSAL
606- * int2 = OpenSSL::ASN1.decode(raw_int)
607- * puts int2.value # => 1
608- *
609- * == Example - Decoding an explicitly tagged INTEGER
610- * int = OpenSSL::ASN1::Integer.new(1, 0, :EXPLICIT) # explicit 0-tagged
611- * seq = OpenSSL::ASN1::Sequence.new( [int] )
612- * der = seq.to_der
613- * asn1 = OpenSSL::ASN1.decode(der)
614- * # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0
615- * # @indefinite_length=false,
616- * # @tag=16,
617- * # @tag_class=:UNIVERSAL,
618- * # @tagging=nil,
619- * # @value=
620- * # [#<OpenSSL::ASN1::ASN1Data:0x87326f4
621- * # @indefinite_length=false,
622- * # @tag=0,
623- * # @tag_class=:CONTEXT_SPECIFIC,
624- * # @value=
625- * # [#<OpenSSL::ASN1::Integer:0x85bf308
626- * # @indefinite_length=false,
627- * # @tag=2,
628- * # @tag_class=:UNIVERSAL
629- * # @tagging=nil,
630- * # @value=1>]>]>
631- * int2 = asn1.value[0].value[0]
632- * puts int2.value # => 1
633- */
634- cASN1Data = rb_define_class_under (mASN1 , "ASN1Data" , rb_cObject );
635424
636- /* Document-class: OpenSSL::ASN1::Primitive
637- *
638- * The parent class for all primitive encodings. Attributes are the same as
639- * for ASN1Data, with the addition of _tagging_.
640- * Primitive values can never be encoded with indefinite length form, thus
641- * it is not possible to set the _indefinite_length_ attribute for Primitive
642- * and its sub-classes.
643- *
644- * == Primitive sub-classes and their mapping to Ruby classes
645- * * OpenSSL::ASN1::EndOfContent <=> _value_ is always +nil+
646- * * OpenSSL::ASN1::Boolean <=> _value_ is +true+ or +false+
647- * * OpenSSL::ASN1::Integer <=> _value_ is an OpenSSL::BN
648- * * OpenSSL::ASN1::BitString <=> _value_ is a String
649- * * OpenSSL::ASN1::OctetString <=> _value_ is a String
650- * * OpenSSL::ASN1::Null <=> _value_ is always +nil+
651- * * OpenSSL::ASN1::Object <=> _value_ is a String
652- * * OpenSSL::ASN1::Enumerated <=> _value_ is an OpenSSL::BN
653- * * OpenSSL::ASN1::UTF8String <=> _value_ is a String
654- * * OpenSSL::ASN1::NumericString <=> _value_ is a String
655- * * OpenSSL::ASN1::PrintableString <=> _value_ is a String
656- * * OpenSSL::ASN1::T61String <=> _value_ is a String
657- * * OpenSSL::ASN1::VideotexString <=> _value_ is a String
658- * * OpenSSL::ASN1::IA5String <=> _value_ is a String
659- * * OpenSSL::ASN1::UTCTime <=> _value_ is a Time
660- * * OpenSSL::ASN1::GeneralizedTime <=> _value_ is a Time
661- * * OpenSSL::ASN1::GraphicString <=> _value_ is a String
662- * * OpenSSL::ASN1::ISO64String <=> _value_ is a String
663- * * OpenSSL::ASN1::GeneralString <=> _value_ is a String
664- * * OpenSSL::ASN1::UniversalString <=> _value_ is a String
665- * * OpenSSL::ASN1::BMPString <=> _value_ is a String
666- *
667- * == OpenSSL::ASN1::BitString
668- *
669- * === Additional attributes
670- * _unused_bits_: if the underlying BIT STRING's
671- * length is a multiple of 8 then _unused_bits_ is 0. Otherwise
672- * _unused_bits_ indicates the number of bits that are to be ignored in
673- * the final octet of the BitString's _value_.
674- *
675- * == OpenSSL::ASN1::ObjectId
676- *
677- * NOTE: While OpenSSL::ASN1::ObjectId.new will allocate a new ObjectId,
678- * it is not typically allocated this way, but rather that are received from
679- * parsed ASN1 encodings.
680- *
681- * === Additional attributes
682- * * _sn_: the short name as defined in <openssl/objects.h>.
683- * * _ln_: the long name as defined in <openssl/objects.h>.
684- * * _oid_: the object identifier as a String, e.g. "1.2.3.4.5"
685- * * _short_name_: alias for _sn_.
686- * * _long_name_: alias for _ln_.
687- *
688- * == Examples
689- * With the Exception of OpenSSL::ASN1::EndOfContent, each Primitive class
690- * constructor takes at least one parameter, the _value_.
691- *
692- * === Creating EndOfContent
693- * eoc = OpenSSL::ASN1::EndOfContent.new
694- *
695- * === Creating any other Primitive
696- * prim = <class>.new(value) # <class> being one of the sub-classes except EndOfContent
697- * prim_zero_tagged_implicit = <class>.new(value, 0, :IMPLICIT)
698- * prim_zero_tagged_explicit = <class>.new(value, 0, :EXPLICIT)
699- */
425+ cASN1Data = rb_define_class_under (mASN1 , "ASN1Data" , rb_cObject );
700426 cASN1Primitive = rb_define_class_under (mASN1 , "Primitive" , cASN1Data );
701427
702- /* Document-class: OpenSSL::ASN1::Constructive
703- *
704- * The parent class for all constructed encodings. The _value_ attribute
705- * of a Constructive is always an Array. Attributes are the same as
706- * for ASN1Data, with the addition of _tagging_.
707- *
708- * == SET and SEQUENCE
709- *
710- * Most constructed encodings come in the form of a SET or a SEQUENCE.
711- * These encodings are represented by one of the two sub-classes of
712- * Constructive:
713- * * OpenSSL::ASN1::Set
714- * * OpenSSL::ASN1::Sequence
715- * Please note that tagged sequences and sets are still parsed as
716- * instances of ASN1Data. Find further details on tagged values
717- * there.
718- *
719- * === Example - constructing a SEQUENCE
720- * int = OpenSSL::ASN1::Integer.new(1)
721- * str = OpenSSL::ASN1::PrintableString.new('abc')
722- * sequence = OpenSSL::ASN1::Sequence.new( [ int, str ] )
723- *
724- * === Example - constructing a SET
725- * int = OpenSSL::ASN1::Integer.new(1)
726- * str = OpenSSL::ASN1::PrintableString.new('abc')
727- * set = OpenSSL::ASN1::Set.new( [ int, str ] )
728- */
729428 cASN1Constructive = rb_define_class_under (mASN1 ,"Constructive" , cASN1Data );
730-
731429#define OSSL_ASN1_DEFINE_CLASS (name , super ) \
732430do{\
733431 cASN1##name = rb_define_class_under(mASN1, #name, cASN1##super);\
@@ -761,10 +459,6 @@ do{\
761459 OSSL_ASN1_DEFINE_CLASS (EndOfContent , Data );
762460
763461
764- /* Document-class: OpenSSL::ASN1::ObjectId
765- *
766- * Represents the primitive object id for OpenSSL::ASN1
767- */
768462#if 0
769463 cASN1ObjectId = rb_define_class_under (mASN1 , "ObjectId" , cASN1Primitive ); /* let rdoc know */
770464#endif
0 commit comments