@@ -649,6 +649,69 @@ public void ISpecificRecordPayloadEncryption()
649
649
Assert . True ( pic . SequenceEqual ( result . picture ) ) ;
650
650
}
651
651
652
+ [ Fact ]
653
+ public void ISpecificRecordEncryptionAlternateKeks ( )
654
+ {
655
+ var schemaStr = "{\" type\" :\" record\" ,\" name\" :\" UserWithPic\" ,\" namespace\" :\" Confluent.Kafka.Examples.AvroSpecific" +
656
+ "\" ,\" fields\" :[{\" name\" :\" name\" ,\" type\" :\" string\" },{\" name\" :\" favorite_number\" ," +
657
+ "\" type\" :[\" int\" ,\" null\" ]},{\" name\" :\" favorite_color\" ,\" type\" :[\" string\" ,\" null\" ]}," +
658
+ "{\" name\" :\" picture\" ,\" type\" :[\" null\" ,\" bytes\" ],\" default\" :null}]}" ;
659
+
660
+ var schema = new RegisteredSchema ( "topic-value" , 1 , 1 , schemaStr , SchemaType . Avro , null ) ;
661
+ schema . Metadata = new Metadata ( new Dictionary < string , ISet < string > >
662
+ {
663
+ [ "Confluent.Kafka.Examples.AvroSpecific.UserWithPic.name" ] = new HashSet < string > { "PII" } ,
664
+ [ "Confluent.Kafka.Examples.AvroSpecific.UserWithPic.picture" ] = new HashSet < string > { "PII" }
665
+
666
+ } , new Dictionary < string , string > ( ) , new HashSet < string > ( )
667
+ ) ;
668
+ schema . RuleSet = new RuleSet ( new List < Rule > ( ) , new List < Rule > ( ) ,
669
+ new List < Rule >
670
+ {
671
+ new Rule ( "encryptPII" , RuleKind . Transform , RuleMode . WriteRead , "ENCRYPT_PAYLOAD" , null ,
672
+ new Dictionary < string , string >
673
+ {
674
+ [ "encrypt.kek.name" ] = "kek1" ,
675
+ [ "encrypt.kms.type" ] = "local-kms" ,
676
+ [ "encrypt.kms.key.id" ] = "mykey"
677
+ } )
678
+ }
679
+ ) ;
680
+ store [ schemaStr ] = 1 ;
681
+ subjectStore [ "topic-value" ] = new List < RegisteredSchema > { schema } ;
682
+ var config = new AvroSerializerConfig
683
+ {
684
+ AutoRegisterSchemas = false ,
685
+ UseLatestVersion = true
686
+ } ;
687
+ config . Set ( "rules.secret" , "mysecret" ) ;
688
+ config . Set ( "rules.encrypt.alternate.kms.key.ids" , "mykey2,mykey3" ) ;
689
+ RuleRegistry ruleRegistry = new RuleRegistry ( ) ;
690
+ IRuleExecutor ruleExecutor = new EncryptionExecutor ( dekRegistryClient , clock ) ;
691
+ ruleRegistry . RegisterExecutor ( ruleExecutor ) ;
692
+ var serializer = new AvroSerializer < UserWithPic > ( schemaRegistryClient , config , ruleRegistry ) ;
693
+ var deserializer = new AvroDeserializer < UserWithPic > ( schemaRegistryClient , null , ruleRegistry ) ;
694
+
695
+ var pic = new byte [ ] { 1 , 2 , 3 } ;
696
+ var user = new UserWithPic ( )
697
+ {
698
+ favorite_color = "blue" ,
699
+ favorite_number = 100 ,
700
+ name = "awesome" ,
701
+ picture = pic
702
+ } ;
703
+
704
+ Headers headers = new Headers ( ) ;
705
+ var bytes = serializer . SerializeAsync ( user , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
706
+ var result = deserializer . DeserializeAsync ( bytes , false , new SerializationContext ( MessageComponentType . Value , testTopic , headers ) ) . Result ;
707
+
708
+ // The user name has been modified
709
+ Assert . Equal ( "awesome" , result . name ) ;
710
+ Assert . Equal ( user . favorite_color , result . favorite_color ) ;
711
+ Assert . Equal ( user . favorite_number , result . favorite_number ) ;
712
+ Assert . True ( pic . SequenceEqual ( result . picture ) ) ;
713
+ }
714
+
652
715
[ Fact ]
653
716
public void ISpecificRecordFieldEncryptionDekRotation ( )
654
717
{
0 commit comments