Skip to content

Commit

Permalink
[refactor] due tests to pass on JRuby 9.4.6.0
Browse files Browse the repository at this point in the history
which has default package access restrictions
  • Loading branch information
kares committed Apr 10, 2024
1 parent a69371b commit 9173da0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/jruby/ext/openssl/impl/ASN1Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ public static String o2a(final ASN1ObjectIdentifier oid) {
return o2a( oid.getId() );
}

//@Deprecated
public static ASN1ObjectIdentifier sym2oid(final String name) {
final String oid = SYM_TO_OID.get( name.toLowerCase() );
return oid == null ? null : new ASN1ObjectIdentifier( oid );
}

public static String name2oid(final String name) {
static String name2oid(final String name) {
return SYM_TO_OID.get( name.toLowerCase() );
}

public static Map<String, String> getOIDLookup() { return SYM_TO_OID; }

static ASN1ObjectIdentifier nid2obj(int nid) {
return new ASN1ObjectIdentifier( NID_TO_OID[ nid ] );
return new ASN1ObjectIdentifier(nid2oid(nid));
}

public static String nid2oid(int nid) {
Expand Down
17 changes: 12 additions & 5 deletions src/test/ruby/pkcs7/test_pkcs7.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_add_signer_to_signed_and_enveloped_should_add_that_to_stack
BIG_ONE = BigInteger::ONE.to_java

def create_signer_info_with_algo(algo)
md5 = AlgorithmIdentifier.new(ASN1Registry.nid2obj(4))
md5 = algorithm_identifier(4)
org.jruby.ext.openssl.impl.SignerInfoWithPkey.new(
org.bouncycastle.asn1.ASN1Integer.new(BIG_ONE),
org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber.new(org.bouncycastle.asn1.x500.X500Name.new("C=SE"), BIG_ONE),
Expand All @@ -421,8 +421,8 @@ def test_add_signer_to_signed_with_new_algo_should_add_that_algo_to_the_algo_lis
p7.type = ASN1Registry::NID_pkcs7_signed

# YES, these numbers are correct. Don't change them. They are OpenSSL internal NIDs
md5 = AlgorithmIdentifier.new(ASN1Registry.nid2obj(4))
md4 = AlgorithmIdentifier.new(ASN1Registry.nid2obj(5))
md5 = algorithm_identifier(4)
md4 = algorithm_identifier(5)

si = create_signer_info_with_algo(md5)
p7.add_signer(si)
Expand Down Expand Up @@ -450,8 +450,8 @@ def test_add_signer_to_signed_and_enveloped_with_new_algo_should_add_that_algo_t
p7.type = ASN1Registry::NID_pkcs7_signedAndEnveloped

# YES, these numbers are correct. Don't change them. They are OpenSSL internal NIDs
md5 = AlgorithmIdentifier.new(ASN1Registry.nid2obj(4))
md4 = AlgorithmIdentifier.new(ASN1Registry.nid2obj(5))
md5 = algorithm_identifier(4)
md4 = algorithm_identifier(5)

si = create_signer_info_with_algo(md5)
p7.add_signer(si)
Expand All @@ -473,6 +473,13 @@ def test_add_signer_to_signed_and_enveloped_with_new_algo_should_add_that_algo_t
assert p7.get_signed_and_enveloped.md_algs.contains(md5)
end

def algorithm_identifier(nid)
oid = ASN1Registry.nid2oid(nid)
raise "oid for #{nid.inspect} not found!" unless oid
AlgorithmIdentifier.new(org.bouncycastle.asn1.ASN1ObjectIdentifier.new(oid))
end
private :algorithm_identifier

def test_set_content_on_data_throws_exception
p7 = PKCS7.new
p7.type = ASN1Registry::NID_pkcs7_data
Expand Down

0 comments on commit 9173da0

Please sign in to comment.