aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-05-18 01:16:32 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-07-23 13:32:35 +0900
commite69649001f39cb866b8e77c906e52ec891952d38 (patch)
tree2de0144cd537edbc05e237762a4659b934fc6286 /ext/openssl
parent8a80e34b9623bfb13b09a7c973e2815d50440e3b (diff)
downloadruby-openssl-e69649001f39cb866b8e77c906e52ec891952d38.tar.gz
asn1: require tag information when instantiating generic type
Improve the error message of the exception raised when OpenSSL::ASN1::Primitive.new or OpenSSL::ASN1::Constructive.new is called with one argument (which is wrong).
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl_asn1.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 580c4da8..305290f2 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -579,8 +579,8 @@ ossl_asn1_default_tag(VALUE obj)
return NUM2INT(tag);
tmp_class = rb_class_superclass(tmp_class);
}
- ossl_raise(eASN1Error, "universal tag for %"PRIsVALUE" not found",
- rb_obj_class(obj));
+
+ return -1;
}
static int
@@ -1078,9 +1078,12 @@ static VALUE
ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE value, tag, tagging, tag_class;
+ int default_tag;
rb_scan_args(argc, argv, "13", &value, &tag, &tagging, &tag_class);
- if(argc > 1){
+ default_tag = ossl_asn1_default_tag(self);
+
+ if (default_tag == -1 || argc > 1) {
if(NIL_P(tag))
ossl_raise(eASN1Error, "must specify tag number");
if(!NIL_P(tagging) && !SYMBOL_P(tagging))
@@ -1097,7 +1100,7 @@ ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
ossl_raise(eASN1Error, "tag number for Universal too large");
}
else{
- tag = INT2NUM(ossl_asn1_default_tag(self));
+ tag = INT2NUM(default_tag);
tagging = Qnil;
tag_class = sym_UNIVERSAL;
}
@@ -1113,7 +1116,7 @@ ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
static VALUE
ossl_asn1eoc_initialize(VALUE self) {
VALUE tag, tagging, tag_class, value;
- tag = INT2NUM(ossl_asn1_default_tag(self));
+ tag = INT2FIX(0);
tagging = Qnil;
tag_class = sym_UNIVERSAL;
value = rb_str_new("", 0);