source: trunk/gcc/libjava/java/security/MessageDigestSpi.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/* MessageDigestSpi.java --- The message digest service provider interface.
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.security;
39
40/**
41 This is the Service Provider Interface (SPI) for MessageDigest
42 class in java.security. It provides the back end functionality
43 for the MessageDigest class so that it can compute message
44 hashes. The default hashes are SHA-1 and MD5. A message hash
45 takes data of arbitrary length and produces a unique number
46 representing it.
47
48 Cryptography service providers who want to implement their
49 own message digest hashes need only to subclass this class.
50
51 The implementation of a Cloneable interface is left to up to
52 the programmer of a subclass.
53
54 @version 0.0
55
56 @author Mark Benvenuto <ivymccough@worldnet.att.net>
57 */
58public abstract class MessageDigestSpi
59{
60 /**
61 Default constructor of the MessageDigestSpi class
62 */
63 public MessageDigestSpi()
64 {
65 }
66
67 /**
68 Returns the length of the digest. It may be overridden by the
69 provider to return the length of the digest. Default is to
70 return 0. It is concrete for backwards compatibility with JDK1.1
71 message digest classes.
72
73 @return Length of Digest in Bytes
74
75 @since 1.2
76 */
77 protected int engineGetDigestLength()
78 {
79 return 0;
80 }
81
82 /**
83 Updates the digest with the specified byte.
84
85 @param input the byte to update digest with
86 */
87 protected abstract void engineUpdate(byte input);
88
89
90 /**
91 Updates the digest with the specified bytes starting with the
92 offset and proceeding for the specified length.
93
94 @param input the byte array to update digest with
95 @param offset the offset of the byte to start with
96 @param len the number of the bytes to update with
97 */
98 protected abstract void engineUpdate(byte[]input, int offset, int len);
99
100 /**
101 Computes the final digest of the stored bytes and returns
102 them. It performs any necessary padding. The message digest
103 should reset sensitive data after performing the digest.
104
105 @return An array of bytes containing the digest
106 */
107 protected abstract byte[] engineDigest();
108
109 /**
110 Computes the final digest of the stored bytes and returns
111 them. It performs any necessary padding. The message digest
112 should reset sensitive data after performing the digest. This
113 method is left concrete for backwards compatibility with JDK1.1
114 message digest classes.
115
116 @param buf An array of bytes to store the digest
117 @param offset An offset to start storing the digest at
118 @param len The length of the buffer
119 @return Returns the length of the buffer
120
121 @since 1.2
122 */
123 protected int engineDigest(byte[]buf, int offset, int len)
124 throws DigestException
125 {
126 if (engineGetDigestLength() > len)
127 throw new DigestException("Buffer is too small.");
128
129 byte tmp[] = engineDigest();
130 if (tmp.length > len)
131 throw new DigestException("Buffer is too small");
132
133 System.arraycopy(tmp, 0, buf, offset, tmp.length);
134 return tmp.length;
135 }
136
137 /**
138 Resets the digest engine. Reinitializes internal variables
139 and clears sensitive data.
140 */
141 protected abstract void engineReset();
142
143 /**
144 Returns a clone of this class.
145
146 If cloning is not supported, then by default the class throws a
147 CloneNotSupportedException. The MessageDigestSpi provider
148 implementation has to overload this class in order to be
149 cloneable.
150 */
151 public Object clone() throws CloneNotSupportedException
152 {
153 if (this instanceof Cloneable)
154 return super.clone();
155 else
156 throw new CloneNotSupportedException();
157 }
158}
Note: See TracBrowser for help on using the repository browser.