Class: Krypt::ASN1::Primitive
- Defined in:
- ext/krypt/core/krypt_asn1.c,
ext/krypt/core/krypt_asn1.c
Overview
The parent class for all primitive encodings. Attributes are the same as
for ASN1Data.
Primitive values can never be infinite length encodings, thus it is not
possible to set the infinite_length attribute for Primitive and its
sub-classes.
Primitive sub-classes and their mapping to Ruby classes
- Krypt::ASN1::EndOfContents <=>
valueis alwaysnil - Krypt::ASN1::Boolean <=>
valueis aBoolean - Krypt::ASN1::Integer <=>
valueis aNumber - Krypt::ASN1::BitString <=>
valueis aString - Krypt::ASN1::OctetString <=>
valueis aString - Krypt::ASN1::Null <=>
valueis alwaysnil - Krypt::ASN1::Object <=>
valueis aString - Krypt::ASN1::Enumerated <=>
valueis aNumber - Krypt::ASN1::UTF8String <=>
valueis aString - Krypt::ASN1::NumericString <=>
valueis aString - Krypt::ASN1::PrintableString <=>
valueis aString - Krypt::ASN1::T61String <=>
valueis aString - Krypt::ASN1::VideotexString <=>
valueis aString - Krypt::ASN1::IA5String <=>
valueis aString - Krypt::ASN1::UTCTime <=>
valueis aTime(or a Number when creating them) - Krypt::ASN1::GeneralizedTime <=>
valueis aTime(or a Number when creating them) - Krypt::ASN1::GraphicString <=>
valueis aString - Krypt::ASN1::ISO64String <=>
valueis aString - Krypt::ASN1::GeneralString <=>
valueis aString - Krypt::ASN1::UniversalString <=>
valueis aString - Krypt::ASN1::BMPString <=>
valueis aString
Krypt::ASN1::BitString
Additional attribute
unused_bits: if the underlying BIT STRING's
length is a multiple of 8 then unused_bits is 0. Otherwise
unused_bits indicates the number of bits that are to be ignored in
the final octet of the +BitString+'s value.
Examples
With the Exception of Krypt::ASN1::EndOfContents and Krypt::ASN1::Null,
each Primitive class constructor takes at least one parameter, the
value. Since the value of the former two is always nil, they also
support a no-arg constructor.
Creating EndOfContents and Null
eoc = Krypt::ASN1::EndOfContents.new null = Krypt::ASN1::Null.new
Creating any other Primitive
prim =
Instance Method Summary collapse
-
#new(value, tag, tag_class) ⇒ ASN1Data
constructor
value: the value to be associated.
Methods inherited from ASN1Data
#<=>, #encode_to, #infinite_length, #infinite_length=, #tag, #tag=, #tag_class, #tag_class=, #to_der, #value, #value=
Constructor Details
#new(value, tag, tag_class) ⇒ ASN1Data
value: the value to be associated. See Primitive for the mappings between ASN.1 types and Ruby types.tag: aNumberrepresenting this value's tag.tag_class: aSymbolrepresenting one of the four valid tag classes:UNIVERSAL,:CONTEXT_SPECIFIC,:APPLICATIONor:PRIVATE.
Creates an ASN1Data from scratch.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'ext/krypt/core/krypt_asn1.c', line 359
static VALUE
krypt_asn1_data_initialize(VALUE self, VALUE value, VALUE vtag, VALUE vtag_class)
{
ID stag_class;
int tag, tag_class, is_constructed;
krypt_asn1_data *data;
int_validate_tag_and_class(vtag, vtag_class);
tag = NUM2INT(vtag);
stag_class = SYM2ID(vtag_class);
if (stag_class == sKrypt_TC_EXPLICIT)
rb_raise(eKryptASN1Error, "Explicit tagging is only supported for explicit UNIVERSAL sub classes of ASN1Data");
if (stag_class == sKrypt_TC_UNIVERSAL && tag > 30)
rb_raise(eKryptASN1Error, "Tag too large for UNIVERSAL tag class");
if ((tag_class = krypt_asn1_tag_class_for_id(stag_class)) == KRYPT_ERR)
rb_raise(eKryptASN1Error, "Unknown tag class");
is_constructed = rb_respond_to(value, sKrypt_ID_EACH);
int_asn1_data_initialize(self, tag, tag_class, is_constructed, 0);
int_asn1_data_get(self, data);
data->update_cb = int_asn1_data_update_cb;
int_asn1_data_set_tag(self, vtag);
int_asn1_data_set_tag_class(self, vtag_class);
int_asn1_data_set_infinite_length(self, Qfalse);
int_asn1_data_set_value(self, value);
int_asn1_data_set_modified(data, 1); /* newly created is modified by default */
return self;
}
|