Skip to content

Commit

Permalink
added filter encode to search
Browse files Browse the repository at this point in the history
  • Loading branch information
royb committed Apr 26, 2023
1 parent b9b03cc commit e8c409a
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,59 @@ public Collection engineGetCRLs(CRLSelector selector)

return crlSet;
}
private static String[] FILTER_ESCAPE_TABLE = new String['\\' + 1];


static {

// Filter encoding table -------------------------------------

// fill with char itself
for (char c = 0; c < FILTER_ESCAPE_TABLE.length; c++) {
FILTER_ESCAPE_TABLE[c] = String.valueOf(c);
}

// escapes (RFC2254)
FILTER_ESCAPE_TABLE['*'] = "\\2a";
FILTER_ESCAPE_TABLE['('] = "\\28";
FILTER_ESCAPE_TABLE[')'] = "\\29";
FILTER_ESCAPE_TABLE['\\'] = "\\5c";
FILTER_ESCAPE_TABLE[0] = "\\00";

}

/**
* Escape a value for use in a filter.
* @param value the value to escape.
* @return a properly escaped representation of the supplied value.
*/
private String filterEncode(String value)
{
if (value == null)
{
return null;
}

// make buffer roomy
StringBuilder encodedValue = new StringBuilder(value.length() * 2);

int length = value.length();

for (int i = 0; i < length; i++) {

char c = value.charAt(i);

if (c < FILTER_ESCAPE_TABLE.length) {
encodedValue.append(FILTER_ESCAPE_TABLE[c]);
}
else {
// default: add the char
encodedValue.append(c);
}
}

return encodedValue.toString();
}

/**
* Returns a Set of byte arrays with the certificate or CRL encodings.
Expand All @@ -388,7 +441,8 @@ public Collection engineGetCRLs(CRLSelector selector)
private Set search(String attributeName, String attributeValue,
String[] attrs) throws CertStoreException
{
String filter = attributeName + "=" + attributeValue;
String filter = attributeName + "=" + filterEncode(attributeValue);
System.out.println(filter);
if (attributeName == null)
{
filter = null;
Expand Down

0 comments on commit e8c409a

Please sign in to comment.