diff --git a/src/main/java/xades4j/verification/DistinguishedNameComparer.java b/src/main/java/xades4j/verification/DistinguishedNameComparer.java index a6c84a27..3e3f4fab 100644 --- a/src/main/java/xades4j/verification/DistinguishedNameComparer.java +++ b/src/main/java/xades4j/verification/DistinguishedNameComparer.java @@ -30,11 +30,13 @@ class DistinguishedNameComparer { private final X500ExtensibleNameStyle x500NameStyle; + private final X500NameStyleProvider x500NameStyleProvider; @Inject - DistinguishedNameComparer(X500ExtensibleNameStyle x500NameStyle) + DistinguishedNameComparer(X500ExtensibleNameStyle x500NameStyle, X500NameStyleProvider x500NameStyleProvider) { this.x500NameStyle = x500NameStyle; + this.x500NameStyleProvider = x500NameStyleProvider; } /** @@ -43,7 +45,7 @@ class DistinguishedNameComparer boolean areEqual(X500Principal parsedDn, String stringDn) { X500Name first = X500Name.getInstance(parsedDn.getEncoded()); - X500Name second = new X500Name(this.x500NameStyle, stringDn); + X500Name second = X500Name.getInstance(this.x500NameStyle, this.x500NameStyleProvider.fromString(stringDn).getEncoded()); return first.equals(second); } } diff --git a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java index 013ee631..329c5d64 100644 --- a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java +++ b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java @@ -13,6 +13,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import xades4j.providers.X500NameStyleProvider; import xades4j.providers.impl.DefaultX500NameStyleProvider; import xades4j.utils.RFC4519ExtensibleStyle; import xades4j.utils.SignatureServicesTestBase; @@ -75,19 +76,21 @@ private static X509Certificate certFromFile(String filePath) throws Exception private final String issuerDn; private final X509Certificate cert; private final RFC4519ExtensibleStyle nameStyle; + private final X500NameStyleProvider x500NameStyleProvider; public DistinguishedNameComparerTest(String issuerDn, X509Certificate cert) throws IOException { this.issuerDn = issuerDn; this.cert = cert; this.nameStyle = new RFC4519ExtensibleStyle(); + this.x500NameStyleProvider = new DefaultX500NameStyleProvider(this.nameStyle); } @Test public void canCompare() { X500Principal principal = cert.getIssuerX500Principal(); - DistinguishedNameComparer comparer = new DistinguishedNameComparer(nameStyle); + DistinguishedNameComparer comparer = new DistinguishedNameComparer(this.nameStyle, this.x500NameStyleProvider); assertTrue(comparer.areEqual(principal, issuerDn)); }