Credential
using Relativity.Transfer.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace Relativity.Transfer
{
public sealed class Credential
{
private readonly Dictionary<string, byte[]> securedSecrets = new Dictionary<string, byte[]>();
public int ArtifactId { get; }
public string CredentialType { get; }
public string Name { get; }
internal IReadOnlyDictionary<string, byte[]> SecretValues => 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)) {
byte[] value = SecretValues[key];
return value.UnprotectData();
}
return null;
}
}
}