// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Xunit; namespace Microsoft.AspNetCore.DataProtection { /// /// Helpful ISecret-based assertions. /// public static class SecretAssert { /// /// Asserts that two instances contain the same material. /// public static void Equal(ISecret secret1, ISecret secret2) { Assert.Equal(SecretToBase64String(secret1), SecretToBase64String(secret2)); } /// /// Asserts that has the length specified by . /// public static void LengthIs(int expectedLengthInBits, ISecret secret) { Assert.Equal(expectedLengthInBits, checked(secret.Length * 8)); } /// /// Asserts that two instances do not contain the same material. /// public static void NotEqual(ISecret secret1, ISecret secret2) { Assert.NotEqual(SecretToBase64String(secret1), SecretToBase64String(secret2)); } private static string SecretToBase64String(ISecret secret) { byte[] secretBytes = new byte[secret.Length]; secret.WriteSecretIntoBuffer(new ArraySegment(secretBytes)); return Convert.ToBase64String(secretBytes); } } }