454 |
454 |
} ossl_asn1_info_t;
|
455 |
455 |
|
456 |
456 |
static ossl_asn1_info_t ossl_asn1_info[] = {
|
457 |
|
{ "EOC", &cASN1EndOfContent, }, /* 0 */
|
|
457 |
{ "END_OF_CONTENT", &cASN1EndOfContent, }, /* 0 */
|
458 |
458 |
{ "BOOLEAN", &cASN1Boolean, }, /* 1 */
|
459 |
459 |
{ "INTEGER", &cASN1Integer, }, /* 2 */
|
460 |
460 |
{ "BIT_STRING", &cASN1BitString, }, /* 3 */
|
... | ... | |
487 |
487 |
{ "BMPSTRING", &cASN1BMPString, }, /* 30 */
|
488 |
488 |
};
|
489 |
489 |
|
|
490 |
|
|
491 |
|
490 |
492 |
int ossl_asn1_info_size = (sizeof(ossl_asn1_info)/sizeof(ossl_asn1_info[0]));
|
491 |
493 |
|
|
494 |
static VALUE class_tag_map;
|
|
495 |
|
492 |
496 |
static int ossl_asn1_default_tag(VALUE obj);
|
493 |
497 |
|
|
498 |
static VALUE
|
|
499 |
ossl_asn1_default_tag_class(VALUE self, VALUE klass)
|
|
500 |
{
|
|
501 |
VALUE tag = rb_hash_lookup(class_tag_map, klass);
|
|
502 |
if (tag != Qnil) {
|
|
503 |
return tag;
|
|
504 |
}
|
|
505 |
|
|
506 |
ossl_raise(eASN1Error, "universal tag for %s not found",
|
|
507 |
rb_class2name(klass));
|
|
508 |
|
|
509 |
return Qnil; /* dummy */
|
|
510 |
}
|
|
511 |
|
|
512 |
static VALUE
|
|
513 |
ossl_asn1_default_tag_public(VALUE self, VALUE obj)
|
|
514 |
{
|
|
515 |
return INT2NUM(ossl_asn1_default_tag(obj));
|
|
516 |
}
|
|
517 |
|
494 |
518 |
ASN1_TYPE*
|
495 |
519 |
ossl_asn1_get_asn1type(VALUE obj)
|
496 |
520 |
{
|
... | ... | |
570 |
594 |
static int
|
571 |
595 |
ossl_asn1_default_tag(VALUE obj)
|
572 |
596 |
{
|
573 |
|
int i;
|
|
597 |
VALUE tmp_class = CLASS_OF(obj);
|
|
598 |
while (tmp_class) {
|
|
599 |
VALUE tag = rb_hash_lookup(class_tag_map, tmp_class);
|
|
600 |
if (tag != Qnil) {
|
|
601 |
return NUM2INT(tag);
|
|
602 |
}
|
|
603 |
tmp_class = RCLASS_SUPER(tmp_class);
|
|
604 |
}
|
574 |
605 |
|
575 |
|
for(i = 0; i < ossl_asn1_info_size; i++){
|
576 |
|
if(ossl_asn1_info[i].klass &&
|
577 |
|
rb_obj_is_kind_of(obj, *ossl_asn1_info[i].klass)){
|
578 |
|
return i;
|
579 |
|
}
|
580 |
|
}
|
581 |
606 |
ossl_raise(eASN1Error, "universal tag for %s not found",
|
582 |
607 |
rb_class2name(CLASS_OF(obj)));
|
583 |
608 |
|
... | ... | |
841 |
866 |
ossl_asn1_set_infinite_length(asn1data, Qtrue);
|
842 |
867 |
else
|
843 |
868 |
ossl_asn1_set_infinite_length(asn1data, Qfalse);
|
844 |
|
|
|
869 |
|
845 |
870 |
rb_ary_push(ary, asn1data);
|
846 |
871 |
length -= len;
|
847 |
872 |
if(once) break;
|
... | ... | |
1190 |
1215 |
rb_define_module_function(mASN1, "traverse", ossl_asn1_traverse, 1);
|
1191 |
1216 |
rb_define_module_function(mASN1, "decode", ossl_asn1_decode, 1);
|
1192 |
1217 |
rb_define_module_function(mASN1, "decode_all", ossl_asn1_decode_all, 1);
|
|
1218 |
rb_define_module_function(mASN1, "default_tag_of_class", ossl_asn1_default_tag_class, 1);
|
|
1219 |
rb_define_module_function(mASN1, "default_tag", ossl_asn1_default_tag_public, 1);
|
1193 |
1220 |
ary = rb_ary_new();
|
1194 |
1221 |
rb_define_const(mASN1, "UNIVERSAL_TAG_NAME", ary);
|
1195 |
1222 |
for(i = 0; i < ossl_asn1_info_size; i++){
|
... | ... | |
1260 |
1287 |
rb_attr(cASN1BitString, rb_intern("unused_bits"), 1, 1, 0);
|
1261 |
1288 |
|
1262 |
1289 |
rb_define_method(cASN1EndOfContent, "initialize", ossl_asn1eoc_initialize, 0);
|
|
1290 |
|
|
1291 |
class_tag_map = rb_hash_new();
|
|
1292 |
rb_hash_aset(class_tag_map, cASN1EndOfContent, INT2NUM(0));
|
|
1293 |
rb_hash_aset(class_tag_map, cASN1Boolean, INT2NUM(1));
|
|
1294 |
rb_hash_aset(class_tag_map, cASN1Integer, INT2NUM(2));
|
|
1295 |
rb_hash_aset(class_tag_map, cASN1BitString, INT2NUM(3));
|
|
1296 |
rb_hash_aset(class_tag_map, cASN1OctetString, INT2NUM(4));
|
|
1297 |
rb_hash_aset(class_tag_map, cASN1Null, INT2NUM(5));
|
|
1298 |
rb_hash_aset(class_tag_map, cASN1ObjectId, INT2NUM(6));
|
|
1299 |
rb_hash_aset(class_tag_map, cASN1Enumerated, INT2NUM(10));
|
|
1300 |
rb_hash_aset(class_tag_map, cASN1UTF8String, INT2NUM(12));
|
|
1301 |
rb_hash_aset(class_tag_map, cASN1Sequence, INT2NUM(16));
|
|
1302 |
rb_hash_aset(class_tag_map, cASN1Set, INT2NUM(17));
|
|
1303 |
rb_hash_aset(class_tag_map, cASN1NumericString, INT2NUM(18));
|
|
1304 |
rb_hash_aset(class_tag_map, cASN1PrintableString, INT2NUM(19));
|
|
1305 |
rb_hash_aset(class_tag_map, cASN1T61String, INT2NUM(20));
|
|
1306 |
rb_hash_aset(class_tag_map, cASN1VideotexString, INT2NUM(21));
|
|
1307 |
rb_hash_aset(class_tag_map, cASN1IA5String, INT2NUM(22));
|
|
1308 |
rb_hash_aset(class_tag_map, cASN1UTCTime, INT2NUM(23));
|
|
1309 |
rb_hash_aset(class_tag_map, cASN1GeneralizedTime, INT2NUM(24));
|
|
1310 |
rb_hash_aset(class_tag_map, cASN1GraphicString, INT2NUM(25));
|
|
1311 |
rb_hash_aset(class_tag_map, cASN1ISO64String, INT2NUM(26));
|
|
1312 |
rb_hash_aset(class_tag_map, cASN1GeneralString, INT2NUM(27));
|
|
1313 |
rb_hash_aset(class_tag_map, cASN1UniversalString, INT2NUM(28));
|
|
1314 |
rb_hash_aset(class_tag_map, cASN1BMPString, INT2NUM(30));
|
|
1315 |
|
|
1316 |
rb_define_const(mASN1, "CLASS_TAG_MAP", class_tag_map);
|
1263 |
1317 |
}
|
1264 |
1318 |
|