Beispiel #1
0
        public void EncryptJsonThrowsWhenCryptoIsNull()
        {
            var json          = "{\"foo\":\"abc\",\"bar\":123,\"baz\":true,\"qux\":[1,2,3],\"garply\":{\"grault\":\"xyz\"},\"fred\":null}";
            var keyIdentifier = new object();

            ICrypto crypto = null;

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

        ICrypto crypto = null !;

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

        act.Should().ThrowExactly <ArgumentNullException>();
    }
Beispiel #3
0
 /// <summary>
 /// Encrypts 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 encryption operations
 /// on field values.
 /// </param>
 /// <param name="jsonString">A string containing an json document.</param>
 /// <param name="jsonPathToEncrypt">The JSONPath of the field to encrypt.</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 encrypted.</returns>
 public static string EncryptJson(this ICrypto crypto, string jsonString, string jsonPathToEncrypt, string credentialName = null) =>
 crypto.EncryptJson(jsonString, new[] { jsonPathToEncrypt }, credentialName);