public void DeserializeTheSameAsSqlServer(int plaintext) { Database.Insert(new SqlParameter("@parameter", SqlDbType.Int) { Value = plaintext }); byte[] ciphertextBytes = Database.SelectCiphertext(SqlDbType.Int); byte[] plaintextBytes = deterministicEncryptionAlgorithm.Decrypt(ciphertextBytes); SqlIntSerializer serializer = new SqlIntSerializer(); int expectedPlaintext = serializer.Deserialize(plaintextBytes); int actualPlaintext = (int)Database.SelectPlaintext(SqlDbType.Int); Assert.Equal(expectedPlaintext, actualPlaintext); }
public void SerializeTheSameAsSqlServer(int plaintext) { SqlIntSerializer serializer = new SqlIntSerializer(); byte[] serializedPlaintext = serializer.Serialize(plaintext); byte[] expectedCiphertext = deterministicEncryptionAlgorithm.Encrypt(serializedPlaintext); Database.Insert(new SqlParameter("@parameter", SqlDbType.Int) { Value = plaintext }); byte[] actualCiphertext = Database.SelectCiphertext(SqlDbType.Int); Assert.Equal(expectedCiphertext, actualCiphertext); }
public void ShouldThrowIfDeserializingLessThanEightBytes(byte[] data) { SqlIntSerializer serializer = new SqlIntSerializer(); Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data)); }
public void ShouldThrowIfDeserializingNull() { SqlIntSerializer serializer = new SqlIntSerializer(); Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null)); }