private void ParseQueryAttribute(string attribute)
{
int separatorIndex = attribute.IndexOf(Pkcs11UriSpec.Pk11QueryAttributeNameAndValueSeparator);
if (separatorIndex == -1)
throw new Pkcs11UriException("Attribute name and value are not separated");
string attributeName = attribute.Substring(0, separatorIndex);
string attributeValue = attribute.Substring(separatorIndex + 1);
switch (attributeName)
{
case Pkcs11UriSpec.Pk11PinSource:
if (_pinSource != null)
throw new Pkcs11UriException("Duplicate attribute " + attributeName + " found in the query component");
if (attributeValue != string.Empty)
{
byte[] bytes = DecodePk11String(attributeName, attributeValue, Pkcs11UriSpec.Pk11QueryAttrValueChars, true);
_pinSource = ConvertUtils.BytesToUtf8String(bytes);
}
else
{
_pinSource = string.Empty;
}
break;
case Pkcs11UriSpec.Pk11PinValue:
if (_pinValue != null)
throw new Pkcs11UriException("Duplicate attribute " + attributeName + " found in the query component");
if (attributeValue != string.Empty)
{
byte[] bytes = DecodePk11String(attributeName, attributeValue, Pkcs11UriSpec.Pk11QueryAttrValueChars, true);
_pinValue = ConvertUtils.BytesToUtf8String(bytes);
}
else
{
_pinValue = string.Empty;
}
break;
case Pkcs11UriSpec.Pk11ModuleName:
if (_moduleName != null)
throw new Pkcs11UriException("Duplicate attribute " + attributeName + " found in the query component");
if (attributeValue != string.Empty)
{
byte[] bytes = DecodePk11String(attributeName, attributeValue, Pkcs11UriSpec.Pk11QueryAttrValueChars, true);
_moduleName = ConvertUtils.BytesToUtf8String(bytes);
}
else
{
_moduleName = string.Empty;
}
break;
case Pkcs11UriSpec.Pk11ModulePath:
if (_modulePath != null)
throw new Pkcs11UriException("Duplicate attribute " + attributeName + " found in the query component");
if (attributeValue != string.Empty)
{
byte[] bytes = DecodePk11String(attributeName, attributeValue, Pkcs11UriSpec.Pk11QueryAttrValueChars, true);
_modulePath = ConvertUtils.BytesToUtf8String(bytes);
}
else
{
_modulePath = string.Empty;
}
break;
default:
if (string.IsNullOrEmpty(attributeName))
throw new Pkcs11UriException("Attribute without name found in the query component");
byte[] vendorAttrName = DecodePk11String(null, attributeName, Pkcs11UriSpec.Pk11VendorAttrNameChars, false);
attributeName = ConvertUtils.BytesToUtf8String(vendorAttrName);
if (attributeValue != string.Empty)
{
byte[] vendorAttrValue = DecodePk11String(attributeName, attributeValue, Pkcs11UriSpec.Pk11QueryAttrValueChars, true);
attributeValue = ConvertUtils.BytesToUtf8String(vendorAttrValue);
}
if (_unknownQueryAttributes.ContainsKey(attributeName))
_unknownQueryAttributes[attributeName].Add(attributeValue);
else
_unknownQueryAttributes.Add(attributeName, new List<string>() { attributeValue });
break;
}
}