6864
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
7014
|
13 |
|
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
6864
|
16 |
Stream subclass:#HashStream
|
7014
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'System-Crypt-Streams'
|
6864
|
21 |
!
|
|
22 |
|
|
23 |
!HashStream class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
Abstract class. Subclasses generate hash values used as checksums
|
|
43 |
or for generating cryptographic signatures.
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Stefan Vogel
|
|
47 |
|
|
48 |
[see also:]
|
|
49 |
SHA1Stream MD5Stream
|
|
50 |
"
|
|
51 |
! !
|
|
52 |
|
|
53 |
!HashStream class methodsFor:'instance creation'!
|
|
54 |
|
7015
|
55 |
new
|
|
56 |
"have to re-allow new - it was disabled in Stream"
|
|
57 |
^ self basicNew initialize
|
|
58 |
|
|
59 |
|
|
60 |
!
|
|
61 |
|
|
62 |
random
|
|
63 |
"create a random number generator using myself"
|
|
64 |
|
|
65 |
^ HashRandom with:self
|
|
66 |
|
|
67 |
"
|
|
68 |
SHA1Stream random next
|
|
69 |
"
|
|
70 |
|
|
71 |
"Modified: / 12.11.1999 / 17:21:17 / stefan"
|
|
72 |
! !
|
|
73 |
|
|
74 |
!HashStream class methodsFor:'utilities'!
|
|
75 |
|
7014
|
76 |
hashValueOf:aStringOrByteArry
|
|
77 |
^ self hashValueOfStream:(aStringOrByteArry readStream)
|
|
78 |
|
|
79 |
"
|
|
80 |
MD5Stream hashValueOf:'BlaBlaBla'
|
|
81 |
"
|
|
82 |
!
|
|
83 |
|
6864
|
84 |
hashValueOfFile:aFilename
|
7014
|
85 |
^ self hashValueOfStream:(aFilename asFilename readStream)
|
|
86 |
|
|
87 |
"
|
|
88 |
MD5Stream hashValueOfFile:'Makefile'
|
|
89 |
"
|
|
90 |
!
|
|
91 |
|
|
92 |
hashValueOfStream:inStream
|
|
93 |
|hashStream|
|
6864
|
94 |
|
|
95 |
hashStream := self new.
|
7014
|
96 |
inStream binary.
|
6864
|
97 |
inStream copyToEndInto:hashStream.
|
|
98 |
inStream close.
|
|
99 |
|
|
100 |
^ hashStream hashValue
|
|
101 |
|
|
102 |
"
|
7014
|
103 |
MD5Stream hashValueOfStream:('Makefile' asFilename readStream)
|
|
104 |
MD5Stream hashValueOfStream:('BlaBla' readStream)
|
6864
|
105 |
"
|
|
106 |
! !
|
|
107 |
|
|
108 |
!HashStream methodsFor:'accessing'!
|
|
109 |
|
|
110 |
contents
|
|
111 |
"return the entire contents of the stream
|
|
112 |
- this is our hashValue."
|
|
113 |
|
|
114 |
^ self hashValue
|
|
115 |
|
|
116 |
"Created: / 17.3.1999 / 15:10:03 / stefan"
|
|
117 |
! !
|
|
118 |
|
|
119 |
!HashStream methodsFor:'not implemented'!
|
|
120 |
|
|
121 |
next
|
|
122 |
^ self shouldNotImplement
|
|
123 |
|
|
124 |
"Created: / 17.3.1999 / 15:11:03 / stefan"
|
|
125 |
! !
|
|
126 |
|
|
127 |
!HashStream methodsFor:'queries'!
|
|
128 |
|
|
129 |
blockSize
|
|
130 |
"the class knows about the basic block size"
|
|
131 |
|
|
132 |
^ self class blockSize
|
|
133 |
|
|
134 |
"Created: / 18.3.1999 / 10:17:02 / stefan"
|
|
135 |
!
|
|
136 |
|
|
137 |
hashSize
|
|
138 |
"the class knows about the basic hash size"
|
|
139 |
|
|
140 |
^ self class hashSize
|
|
141 |
|
|
142 |
"Created: / 18.3.1999 / 10:17:12 / stefan"
|
|
143 |
"Modified: / 15.10.1999 / 11:53:20 / stefan"
|
|
144 |
!
|
|
145 |
|
|
146 |
isReadable
|
|
147 |
"return true, if reading is supported by the recevier.
|
|
148 |
Always return false here"
|
|
149 |
|
|
150 |
^ false
|
|
151 |
|
|
152 |
"Modified: / 17.3.1999 / 15:06:09 / stefan"
|
|
153 |
!
|
|
154 |
|
|
155 |
isWritable
|
|
156 |
"return true, if writing is supported by the recevier.
|
|
157 |
Always return true here"
|
|
158 |
|
|
159 |
^ true
|
|
160 |
|
|
161 |
"Created: / 17.3.1999 / 15:05:49 / stefan"
|
|
162 |
! !
|
|
163 |
|
|
164 |
!HashStream methodsFor:'testing'!
|
|
165 |
|
|
166 |
atEnd
|
|
167 |
"return true if the end of the stream has been reached;
|
|
168 |
this is never reached"
|
|
169 |
|
|
170 |
^ false
|
|
171 |
|
|
172 |
"Created: / 17.3.1999 / 15:08:55 / stefan"
|
|
173 |
! !
|
|
174 |
|
|
175 |
!HashStream methodsFor:'writing'!
|
|
176 |
|
|
177 |
nextPutAll:aCollection
|
|
178 |
"Hash streams handle Strings and ByteArrays in nextPut:"
|
|
179 |
|
|
180 |
aCollection class isBytes ifTrue:[
|
|
181 |
self nextPut:aCollection.
|
|
182 |
] ifFalse:[
|
|
183 |
super nextPutAll:aCollection
|
|
184 |
].
|
|
185 |
|
|
186 |
"Created: / 14.10.1999 / 11:22:50 / stefan"
|
|
187 |
! !
|
|
188 |
|
|
189 |
!HashStream class methodsFor:'documentation'!
|
|
190 |
|
|
191 |
version
|
7015
|
192 |
^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.3 2003-02-07 11:29:26 penk Exp $'
|
6864
|
193 |
! !
|