1 7 8 package java.security; 9 10 import java.util.*; 11 import java.lang.*; 12 import java.io.IOException ; 13 import java.io.ByteArrayOutputStream ; 14 import java.io.PrintStream ; 15 import java.io.InputStream ; 16 import java.io.ByteArrayInputStream ; 17 18 import java.nio.ByteBuffer ; 19 20 import sun.security.jca.JCAUtil; 21 22 41 42 public abstract class MessageDigestSpi { 43 44 59 protected int engineGetDigestLength() { 60 return 0; 61 } 62 63 68 protected abstract void engineUpdate(byte input); 69 70 81 protected abstract void engineUpdate(byte[] input, int offset, int len); 82 83 93 protected void engineUpdate(ByteBuffer input) { 94 if (input.hasRemaining() == false) { 95 return; 96 } 97 if (input.hasArray()) { 98 byte[] b = input.array(); 99 int ofs = input.arrayOffset(); 100 int pos = input.position(); 101 int lim = input.limit(); 102 engineUpdate(b, ofs + pos, lim - pos); 103 input.position(lim); 104 } else { 105 int len = input.remaining(); 106 byte[] b = new byte[JCAUtil.getTempArraySize(len)]; 107 while (len > 0) { 108 int chunk = Math.min(len, b.length); 109 input.get(b, 0, chunk); 110 engineUpdate(b, 0, chunk); 111 len -= chunk; 112 } 113 } 114 } 115 116 126 protected abstract byte[] engineDigest(); 127 128 158 protected int engineDigest(byte[] buf, int offset, int len) 159 throws DigestException { 160 161 byte[] digest = engineDigest(); 162 if (len < digest.length) 163 throw new DigestException ("partial digests not returned"); 164 if (buf.length - offset < digest.length) 165 throw new DigestException ("insufficient space in the output " 166 + "buffer to store the digest"); 167 System.arraycopy(digest, 0, buf, offset, digest.length); 168 return digest.length; 169 } 170 171 174 protected abstract void engineReset(); 175 176 184 public Object clone() throws CloneNotSupportedException { 185 if (this instanceof Cloneable ) { 186 return super.clone(); 187 } else { 188 throw new CloneNotSupportedException (); 189 } 190 } 191 } 192 | Popular Tags |