/// <summary> /// Convert <see cref="HashAlgorithmKind"/> to <see cref="HashAlgorithm"/> /// </summary> /// <param name="source">The source value</param> /// <returns>The <see cref="ConvertResult{TResult}"/> containing the converted value</returns> public ConvertResult <HashAlgorithm> Convert(HashAlgorithmKind?source) { HashAlgorithm hashAlgorithm = null; if (source.HasValue == true) { switch (source) { case HashAlgorithmKind.SHA256: #pragma warning disable CA2000 // Dispose objects before losing scope hashAlgorithm = SHA256.Create(); #pragma warning restore CA2000 // Dispose objects before losing scope break; case HashAlgorithmKind.SHA384: #pragma warning disable CA2000 // Dispose objects before losing scope hashAlgorithm = SHA384.Create(); #pragma warning restore CA2000 // Dispose objects before losing scope break; case HashAlgorithmKind.SHA512: #pragma warning disable CA2000 // Dispose objects before losing scope hashAlgorithm = SHA512.Create(); #pragma warning restore CA2000 // Dispose objects before losing scope break; default: throw new ArgumentException("Unsupported value", nameof(source)); } } return(ConvertResult.FromReference(hashAlgorithm)); }
/// <summary> /// Convert value /// </summary> /// <param name="source">The source</param> /// <returns>They bearer token key</returns> public ConvertResult <BearerTokenKey> Convert(ApiRequest source) { Argument.NotNull(source, nameof(source)); BearerTokenKey key; switch (source.Credentials.Kind) { case CredentialsKind.Default: key = new BearerTokenKey( source.Context.EndPoint, source.Credentials.Username); break; case CredentialsKind.Environment: key = new BearerTokenKey( source.Context.EndPoint, source.Credentials.Username, source.Credentials.Environment); break; case CredentialsKind.Impersonate: key = new BearerTokenKey( source.Context.EndPoint, source.Credentials.Username, source.Credentials.Environment, source.Credentials.ImpersonateUserId); break; default: throw new InvalidOperationException("Unsupported value: " + source.Credentials.Kind); } var convertResult = ConvertResult.FromReference(key); return(convertResult); }