Method: Krypt::ASN1::ASN1Data#initialize
- Defined in:
- ext/krypt/core/krypt_asn1.c
#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, :APPLICATION or :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;
}
|