Skip to content

Commit

Permalink
Fixed the results of OpenSSL::Timestamp::Response#failure_info
Browse files Browse the repository at this point in the history
Made stored values `Symbol`s instead of `ID`s.

Fixes https://bugs.ruby-lang.org/issues/17625

Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
  • Loading branch information
nobu and xtkoba (Tee KOBAYASHI) committed Feb 14, 2021
1 parent fd39183 commit f2d0046
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ext/openssl/ossl_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ static VALUE cTimestampRequest;
static VALUE cTimestampResponse;
static VALUE cTimestampTokenInfo;
static VALUE cTimestampFactory;
static ID sBAD_ALG, sBAD_REQUEST, sBAD_DATA_FORMAT, sTIME_NOT_AVAILABLE;
static ID sUNACCEPTED_POLICY, sUNACCEPTED_EXTENSION, sADD_INFO_NOT_AVAILABLE;
static ID sSYSTEM_FAILURE;
static VALUE sBAD_ALG, sBAD_REQUEST, sBAD_DATA_FORMAT, sTIME_NOT_AVAILABLE;
static VALUE sUNACCEPTED_POLICY, sUNACCEPTED_EXTENSION, sADD_INFO_NOT_AVAILABLE;
static VALUE sSYSTEM_FAILURE;

static void
ossl_ts_req_free(void *ptr)
Expand Down Expand Up @@ -1247,24 +1247,24 @@ Init_ossl_ts(void)
* timestamp server rejects the message imprint algorithm used in the
* +Request+
*/
sBAD_ALG = rb_intern_const("BAD_ALG");
sBAD_ALG = ID2SYM(rb_intern_const("BAD_ALG"));

/*
* Possible return value for +Response#failure_info+. Indicates that the
* timestamp server was not able to process the +Request+ properly.
*/
sBAD_REQUEST = rb_intern_const("BAD_REQUEST");
sBAD_REQUEST = ID2SYM(rb_intern_const("BAD_REQUEST"));
/*
* Possible return value for +Response#failure_info+. Indicates that the
* timestamp server was not able to parse certain data in the +Request+.
*/
sBAD_DATA_FORMAT = rb_intern_const("BAD_DATA_FORMAT");
sBAD_DATA_FORMAT = ID2SYM(rb_intern_const("BAD_DATA_FORMAT"));

sTIME_NOT_AVAILABLE = rb_intern_const("TIME_NOT_AVAILABLE");
sUNACCEPTED_POLICY = rb_intern_const("UNACCEPTED_POLICY");
sUNACCEPTED_EXTENSION = rb_intern_const("UNACCEPTED_EXTENSION");
sADD_INFO_NOT_AVAILABLE = rb_intern_const("ADD_INFO_NOT_AVAILABLE");
sSYSTEM_FAILURE = rb_intern_const("SYSTEM_FAILURE");
sTIME_NOT_AVAILABLE = ID2SYM(rb_intern_const("TIME_NOT_AVAILABLE"));
sUNACCEPTED_POLICY = ID2SYM(rb_intern_const("UNACCEPTED_POLICY"));
sUNACCEPTED_EXTENSION = ID2SYM(rb_intern_const("UNACCEPTED_EXTENSION"));
sADD_INFO_NOT_AVAILABLE = ID2SYM(rb_intern_const("ADD_INFO_NOT_AVAILABLE"));
sSYSTEM_FAILURE = ID2SYM(rb_intern_const("SYSTEM_FAILURE"));

/* Document-class: OpenSSL::Timestamp
* Provides classes and methods to request, create and validate
Expand Down
5 changes: 5 additions & 0 deletions test/openssl/test_ts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def test_response_creation
assert_equal(token.to_der, resp.token.to_der)
end

def test_response_failure_info
resp = OpenSSL::Timestamp::Response.new("0\"0 \x02\x01\x020\x17\f\x15Invalid TimeStampReq.\x03\x02\x06\x80")
assert_equal(:BAD_ALG, resp.failure_info)
end

def test_response_mandatory_fields
fac = OpenSSL::Timestamp::Factory.new
req = OpenSSL::Timestamp::Request.new
Expand Down

0 comments on commit f2d0046

Please sign in to comment.