Skip to content

Commit

Permalink
Go back to creating X500Name from encoded X500Principal
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgoncalves committed Nov 4, 2018
1 parent 40f96d6 commit 49cb1ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 49cb1ef

Please sign in to comment.