private void Parse(string uri)
{
if (string.IsNullOrEmpty(uri))
throw new ArgumentNullException("uri");
// Check URI scheme
if (!uri.StartsWith(Pkcs11UriSpec.Pk11UriSchemeName + Pkcs11UriSpec.Pk11UriAndPathSeparator, StringComparison.Ordinal))
throw new Pkcs11UriException("Unknown URI scheme name");
// Remove URI prefix
uri = uri.Remove(0, Pkcs11UriSpec.Pk11UriSchemeName.Length + Pkcs11UriSpec.Pk11UriAndPathSeparator.Length);
// Empty PKCS#11 URI is also valid
if (uri == string.Empty)
return;
// Extract path and query parts
string path = null;
string query = null;
int separatorIndex = uri.IndexOf(Pkcs11UriSpec.Pk11PathAndQuerySeparator);
if (separatorIndex == -1)
{
path = uri;
query = string.Empty;
}
else
{
path = uri.Substring(0, separatorIndex);
query = uri.Substring(separatorIndex + 1);
if (string.IsNullOrEmpty(query))
throw new Pkcs11UriException("Question mark is present in the URI but query component is missing");
}
// Parse path attributes
if (!string.IsNullOrEmpty(path))
{
string[] pathAttributes = path.Split(new string[] { Pkcs11UriSpec.Pk11PathAttributesSeparator }, StringSplitOptions.None);
foreach (string pathAttribute in pathAttributes)
ParsePathAttribute(pathAttribute);
}
// Parse query attributes
if (!string.IsNullOrEmpty(query))
{
string[] queryAttributes = query.Split(new string[] { Pkcs11UriSpec.Pk11QueryAttributesSeparator }, StringSplitOptions.None);
foreach (string queryAttribute in queryAttributes)
ParseQueryAttribute(queryAttribute);
}
}