@@ -504,6 +504,47 @@ TDFObject createTDF(InputStream payload, OutputStream outputStream, Config.TDFCo
504504 }
505505 }
506506
507+ for (var assertionConfig : tdfConfig .assertionConfigList ) {
508+ var assertion = new Manifest .Assertion ();
509+ assertion .id = assertionConfig .id ;
510+ assertion .type = assertionConfig .type .toString ();
511+ assertion .scope = assertionConfig .scope .toString ();
512+ assertion .statement = assertionConfig .statement ;
513+ assertion .appliesToState = assertionConfig .appliesToState .toString ();
514+
515+ var assertionHashAsHex = assertion .hash ();
516+ byte [] assertionHash ;
517+ if (tdfConfig .hexEncodeRootAndSegmentHashes ) {
518+ assertionHash = assertionHashAsHex .getBytes (StandardCharsets .UTF_8 );
519+ } else {
520+ try {
521+ assertionHash = Hex .decodeHex (assertionHashAsHex );
522+ } catch (DecoderException e ) {
523+ throw new SDKException ("error decoding assertion hash" , e );
524+ }
525+ }
526+ byte [] completeHash = new byte [aggregateHash .size () + assertionHash .length ];
527+ System .arraycopy (aggregateHash .toByteArray (), 0 , completeHash , 0 , aggregateHash .size ());
528+ System .arraycopy (assertionHash , 0 , completeHash , aggregateHash .size (), assertionHash .length );
529+
530+ var encodedHash = Base64 .getEncoder ().encodeToString (completeHash );
531+
532+ var assertionSigningKey = new AssertionConfig .AssertionKey (AssertionConfig .AssertionKeyAlg .HS256 ,
533+ tdfObject .aesGcm .getKey ());
534+ if (assertionConfig .signingKey != null && assertionConfig .signingKey .isDefined ()) {
535+ assertionSigningKey = assertionConfig .signingKey ;
536+ }
537+ var hashValues = new Manifest .Assertion .HashValues (
538+ assertionHashAsHex ,
539+ encodedHash );
540+ try {
541+ assertion .sign (hashValues , assertionSigningKey );
542+ } catch (KeyLengthException e ) {
543+ throw new SDKException ("error signing assertion hash" , e );
544+ }
545+ signedAssertions .add (assertion );
546+ }
547+
507548 for (var binder : tdfConfig .binders ) {
508549 try {
509550 var assertion = binder .bind (tdfObject .manifest , aggregateHash .toByteArray ());
0 commit comments