Пример #1
0
        public void DecryptJsonThrowsWhenCryptoIsNull()
        {
            var json          = "{\"foo\":\"ImFiYyI=\",\"bar\":\"MTIz\",\"baz\":\"dHJ1ZQ==\",\"qux\":\"WzEsMiwzXQ==\",\"garply\":\"eyJncmF1bHQiOiJ4eXoifQ==\",\"fred\":\"bnVsbA==\"}";
            var keyIdentifier = new object();

            ICrypto crypto = null;

            Assert.That(() => crypto.DecryptJson(json, new[] { "$.foo", "$.bar", "$.baz", "$.qux", "$.garply", "$.fred" }, keyIdentifier), Throws.ArgumentNullException);
        }
Пример #2
0
    public static void DecryptJsonThrowsWhenCryptoIsNull()
    {
        var json = "{\"foo\":\"[[\\\"abc\\\"]]\",\"bar\":\"[[123]]\",\"baz\":\"[[true]]\",\"qux\":\"[[[1,2,3]]]\",\"garply\":\"[[{\\\"grault\\\":\\\"xyz\\\"}]]\",\"fred\":\"[[null]]\"}";

        ICrypto crypto = null !;

        var act = () => crypto.DecryptJson(json, new[] { "$.foo", "$.bar", "$.baz", "$.qux", "$.garply", "$.fred" });

        act.Should().ThrowExactly <ArgumentNullException>();
    }
Пример #3
0
 /// <summary>
 /// Decrypts the fields, specified by JSONPath, that are contained in the given json document string.
 /// </summary>
 /// <param name="crypto">
 /// The instance of <see cref="ICrypto"/> that ultimately responsible for performing decryption operations
 /// on field values.
 /// </param>
 /// <param name="jsonString">A string containing an json document.</param>
 /// <param name="jsonPathToDecrypt">The JSONPath of the field to decrypt.</param>
 /// <param name="credentialName">
 /// The name of the credential to use for this encryption operation,
 /// or null to use the default credential.
 /// </param>
 /// <returns>The same json document, except with the specified fields decrypted.</returns>
 public static string DecryptJson(this ICrypto crypto, string jsonString, string jsonPathToDecrypt, string credentialName = null) =>
 crypto.DecryptJson(jsonString, new[] { jsonPathToDecrypt }, credentialName);