src/java.base/share/classes/sun/security/ssl/HandshakeHash.java
changeset 52928 d59955700113
parent 50768 68fa3d4026ea
child 53563 a4b7ea85d668
equal deleted inserted replaced
52927:226c451bd954 52928:d59955700113
   516         T12HandshakeHash(CipherSuite cipherSuite) {
   516         T12HandshakeHash(CipherSuite cipherSuite) {
   517             MessageDigest md =
   517             MessageDigest md =
   518                     JsseJce.getMessageDigest(cipherSuite.hashAlg.name);
   518                     JsseJce.getMessageDigest(cipherSuite.hashAlg.name);
   519             if (md instanceof Cloneable) {
   519             if (md instanceof Cloneable) {
   520                 transcriptHash = new CloneableHash(md);
   520                 transcriptHash = new CloneableHash(md);
       
   521                 this.baos = new ByteArrayOutputStream();
       
   522             } else {
       
   523                 transcriptHash = new NonCloneableHash(md);
   521                 this.baos = null;
   524                 this.baos = null;
   522             } else {
       
   523                 transcriptHash = new NonCloneableHash(md);
       
   524                 this.baos = new ByteArrayOutputStream();
       
   525             }
   525             }
   526         }
   526         }
   527 
   527 
   528         @Override
   528         @Override
   529         public void update(byte[] input, int offset, int length) {
   529         public void update(byte[] input, int offset, int length) {
   548         }
   548         }
   549     }
   549     }
   550 
   550 
   551     static final class T13HandshakeHash implements TranscriptHash {
   551     static final class T13HandshakeHash implements TranscriptHash {
   552         private final TranscriptHash transcriptHash;
   552         private final TranscriptHash transcriptHash;
   553         private final ByteArrayOutputStream baos;
       
   554 
   553 
   555         T13HandshakeHash(CipherSuite cipherSuite) {
   554         T13HandshakeHash(CipherSuite cipherSuite) {
   556             MessageDigest md =
   555             MessageDigest md =
   557                     JsseJce.getMessageDigest(cipherSuite.hashAlg.name);
   556                     JsseJce.getMessageDigest(cipherSuite.hashAlg.name);
   558             if (md instanceof Cloneable) {
   557             if (md instanceof Cloneable) {
   559                 transcriptHash = new CloneableHash(md);
   558                 transcriptHash = new CloneableHash(md);
   560                 this.baos = null;
       
   561             } else {
   559             } else {
   562                 transcriptHash = new NonCloneableHash(md);
   560                 transcriptHash = new NonCloneableHash(md);
   563                 this.baos = new ByteArrayOutputStream();
       
   564             }
   561             }
   565         }
   562         }
   566 
   563 
   567         @Override
   564         @Override
   568         public void update(byte[] input, int offset, int length) {
   565         public void update(byte[] input, int offset, int length) {
   569             transcriptHash.update(input, offset, length);
   566             transcriptHash.update(input, offset, length);
   570             if (baos != null) {
       
   571                 baos.write(input, offset, length);
       
   572             }
       
   573         }
   567         }
   574 
   568 
   575         @Override
   569         @Override
   576         public byte[] digest() {
   570         public byte[] digest() {
   577             return transcriptHash.digest();
   571             return transcriptHash.digest();
   578         }
   572         }
   579 
   573 
   580         @Override
   574         @Override
   581         public byte[] archived() {
   575         public byte[] archived() {
   582             if (baos != null) {
   576             // This method is not necessary in T13
   583                 return baos.toByteArray();
   577             throw new UnsupportedOperationException(
   584             } else {
   578                     "TLS 1.3 does not require archived.");
   585                 return transcriptHash.archived();
       
   586             }
       
   587 
       
   588             // throw new UnsupportedOperationException("Not supported yet.");
       
   589         }
   579         }
   590     }
   580     }
   591 
   581 
   592     static final class CloneableHash implements TranscriptHash {
   582     static final class CloneableHash implements TranscriptHash {
   593         private final MessageDigest md;
   583         private final MessageDigest md;