jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Digest.java
changeset 41471 18c0f074ed97
parent 25859 3317bb8137f4
equal deleted inserted replaced
41455:0875007901f7 41471:18c0f074ed97
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    32 
    32 
    33 import javax.crypto.SecretKey;
    33 import javax.crypto.SecretKey;
    34 
    34 
    35 import sun.nio.ch.DirectBuffer;
    35 import sun.nio.ch.DirectBuffer;
    36 
    36 
       
    37 import sun.security.util.MessageDigestSpi2;
       
    38 
    37 import sun.security.pkcs11.wrapper.*;
    39 import sun.security.pkcs11.wrapper.*;
    38 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
    40 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
    39 
    41 
    40 /**
    42 /**
    41  * MessageDigest implementation class. This class currently supports
    43  * MessageDigest implementation class. This class currently supports
    47  * minimize number of the Java->native transitions.
    49  * minimize number of the Java->native transitions.
    48  *
    50  *
    49  * @author  Andreas Sterbenz
    51  * @author  Andreas Sterbenz
    50  * @since   1.5
    52  * @since   1.5
    51  */
    53  */
    52 final class P11Digest extends MessageDigestSpi implements Cloneable {
    54 final class P11Digest extends MessageDigestSpi implements Cloneable,
       
    55     MessageDigestSpi2 {
    53 
    56 
    54     /* fields initialized, no session acquired */
    57     /* fields initialized, no session acquired */
    55     private final static int S_BLANK    = 1;
    58     private final static int S_BLANK    = 1;
    56 
    59 
    57     /* data in buffer, session acquired, but digest not initialized */
    60     /* data in buffer, session acquired, but digest not initialized */
   231             throw new ProviderException("update() failed", e);
   234             throw new ProviderException("update() failed", e);
   232         }
   235         }
   233     }
   236     }
   234 
   237 
   235     // Called by SunJSSE via reflection during the SSL 3.0 handshake if
   238     // Called by SunJSSE via reflection during the SSL 3.0 handshake if
   236     // the master secret is sensitive. We may want to consider making this
   239     // the master secret is sensitive.
   237     // method public in a future release.
   240     // Note: Change to protected after this method is moved from
   238     protected void implUpdate(SecretKey key) throws InvalidKeyException {
   241     // sun.security.util.MessageSpi2 interface to
   239 
   242     // java.security.MessageDigestSpi class
       
   243     public void engineUpdate(SecretKey key) throws InvalidKeyException {
   240         // SunJSSE calls this method only if the key does not have a RAW
   244         // SunJSSE calls this method only if the key does not have a RAW
   241         // encoding, i.e. if it is sensitive. Therefore, no point in calling
   245         // encoding, i.e. if it is sensitive. Therefore, no point in calling
   242         // SecretKeyFactory to try to convert it. Just verify it ourselves.
   246         // SecretKeyFactory to try to convert it. Just verify it ourselves.
   243         if (key instanceof P11Key == false) {
   247         if (key instanceof P11Key == false) {
   244             throw new InvalidKeyException("Not a P11Key: " + key);
   248             throw new InvalidKeyException("Not a P11Key: " + key);