Credential
using Relativity.Transfer.Resources;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace Relativity.Transfer
{
[DebuggerStepThrough]
public sealed class Credential
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Dictionary<string, byte[]> securedSecrets = new Dictionary<string, byte[]>();
public int ArtifactId { get; }
public string CredentialType { get; }
public string Name { get; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal IReadOnlyDictionary<string, byte[]> SecretValues {
get {
return securedSecrets;
}
}
public Credential(int artifactId, string name, string credentialType, IDictionary<string, string> secrets)
{
if (artifactId < 1) {
string message = string.Format(CultureInfo.CurrentCulture, CoreStrings.ArtifactOutOfRangeExceptionMessage, "Credential");
throw new ArgumentOutOfRangeException("artifactId", message);
}
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
if (string.IsNullOrEmpty(credentialType))
throw new ArgumentNullException("credentialType");
if (secrets == null)
throw new ArgumentNullException("secrets");
ArtifactId = artifactId;
Name = name;
CredentialType = credentialType;
foreach (string key in secrets.Keys) {
securedSecrets.Add(key, secrets[key].ProtectData().ToArray());
}
}
internal string GetSecretValue(string key)
{
if (!SecretValues.ContainsKey(key))
return null;
return SecretValues[key].UnprotectData();
}
}
}