author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 19 Jan 2012 10:06:02 +0000 | |
branch | jv |
changeset 17910 | 8d796ca8bd1d |
parent 17909 | 0ab1deab8e9c |
child 17911 | a99f15c5efa5 |
permissions | -rw-r--r-- |
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 |
" |
|
7014 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
6864 | 14 |
Stream subclass:#HashStream |
7014 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
17735 | 18 |
category:'System-Crypt-Hashing' |
6864 | 19 |
! |
20 |
||
21 |
!HashStream class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
17910 | 40 |
Abstract class. |
41 |
Subclasses generate hash values used as checksums |
|
6864 | 42 |
or for generating cryptographic signatures. |
43 |
||
17910 | 44 |
Notice: due to historic reasons and compatibility with Squeak, |
45 |
there are two modes of operation: |
|
46 |
1) hashFunction mode, in which the hash of a single block of bytes is computed |
|
47 |
2) hashStream mode, in which instances behave like a writeStream, computing and |
|
48 |
updating the hash, as data is sent to it. |
|
49 |
||
50 |
hashFunction mode is called using: #hashValueOf:aStringOrByteArray |
|
51 |
Warning: Not all subclasses support the stream mode |
|
52 |
(especially those which were ported from squeak do not). |
|
53 |
||
6864 | 54 |
[author:] |
55 |
Stefan Vogel |
|
56 |
||
57 |
[see also:] |
|
58 |
SHA1Stream MD5Stream |
|
59 |
" |
|
17910 | 60 |
! |
61 |
||
62 |
examples |
|
63 |
" |
|
64 |
hashFunction mode: |
|
65 |
[exBegin] |
|
66 |
MD5Stream hashValueOf:'hello world' |
|
67 |
MD4Stream hashValueOf:'hello world' |
|
68 |
[exEnd] |
|
69 |
||
70 |
hashStream mode: |
|
71 |
[exBegin] |
|
72 |
|md5| |
|
73 |
||
74 |
md5 := MD5Stream new. |
|
75 |
md5 nextPutAll:'hello world'. |
|
76 |
md5 hashValue |
|
77 |
[exEnd] |
|
78 |
" |
|
6864 | 79 |
! ! |
80 |
||
81 |
!HashStream class methodsFor:'instance creation'! |
|
82 |
||
7015 | 83 |
new |
84 |
"have to re-allow new - it was disabled in Stream" |
|
85 |
^ self basicNew initialize |
|
86 |
||
87 |
||
88 |
! |
|
89 |
||
90 |
random |
|
91 |
"create a random number generator using myself" |
|
92 |
||
93 |
^ HashRandom with:self |
|
94 |
||
95 |
" |
|
96 |
SHA1Stream random next |
|
97 |
" |
|
98 |
||
99 |
"Modified: / 12.11.1999 / 17:21:17 / stefan" |
|
100 |
! ! |
|
101 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
102 |
!HashStream class methodsFor:'compatibility - squeak'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
103 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
104 |
hashMessage:aStringOrByteArrayOrStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
105 |
"SQUEAK compatibility |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
106 |
- but this is a bad choice - squeak uses #digestMessage: at the instance side" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
107 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
108 |
^ self hashValueOf:aStringOrByteArrayOrStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
109 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
110 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
111 |
!HashStream class methodsFor:'queries'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
112 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
113 |
canStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
114 |
"simple hash functions (squeak-ported) cannot stream. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
115 |
Use hashFunction: there" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
116 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
117 |
^ true |
17909 | 118 |
! |
119 |
||
120 |
hashSize |
|
17910 | 121 |
"return the size of the hashvalue returned by instances of this class (in bytes)" |
122 |
||
17909 | 123 |
self subclassResponsibility |
124 |
||
125 |
"Created: / 04-01-2012 / 19:22:32 / cg" |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
126 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
127 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
128 |
!HashStream class methodsFor:'self tests'! |
7042 | 129 |
|
130 |
test |
|
131 |
"test against testVector" |
|
132 |
||
133 |
self testVector do:[:pair | |
|
17910 | 134 |
|data expectedHash expectedHashBytes computedHash hashStream| |
7042 | 135 |
|
136 |
data := pair first. |
|
137 |
expectedHash := pair second. |
|
17754 | 138 |
expectedHash isString ifTrue:[ |
139 |
expectedHashBytes := ByteArray fromHexString:expectedHash |
|
140 |
] ifFalse:[ |
|
141 |
expectedHashBytes := expectedHash |
|
142 |
]. |
|
7042 | 143 |
|
17841 | 144 |
"/ non-stream interface must be implemented by all |
17910 | 145 |
computedHash := self hashValueOf:data. |
146 |
self assert:computedHash = expectedHashBytes message:'Test failed'. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
147 |
self canStream ifTrue:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
148 |
hashStream := self new. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
149 |
hashStream nextPut:data. |
17910 | 150 |
computedHash := hashStream hashValue. |
151 |
self assert:computedHash = expectedHashBytes message:'Test failed' |
|
7042 | 152 |
]. |
153 |
]. |
|
154 |
||
155 |
" |
|
156 |
MD5Stream test. |
|
157 |
SHA1Stream test. |
|
158 |
RipeMD160Stream test. |
|
159 |
" |
|
17910 | 160 |
|
161 |
"Modified: / 10-01-2012 / 22:35:17 / cg" |
|
7042 | 162 |
! |
163 |
||
164 |
testVector |
|
17910 | 165 |
"/ obsolete - moved to TestHashAlgorithms unit test. |
7042 | 166 |
|
167 |
^ self subclassResponsibility |
|
17910 | 168 |
|
169 |
"Modified (comment): / 09-01-2012 / 21:49:59 / cg" |
|
7042 | 170 |
! ! |
171 |
||
7015 | 172 |
!HashStream class methodsFor:'utilities'! |
173 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
174 |
digestMessage:aStringOrByteArrayOrStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
175 |
^ self hashValueOf:aStringOrByteArrayOrStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
176 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
177 |
|
7042 | 178 |
hashValueOf:aStringOrByteArrayOrStream |
179 |
|hashStream| |
|
180 |
||
181 |
hashStream := self new. |
|
17910 | 182 |
aStringOrByteArrayOrStream isStream ifTrue:[ |
183 |
aStringOrByteArrayOrStream copyToEndInto:hashStream. |
|
184 |
] ifFalse:[ |
|
185 |
hashStream nextPutAll:aStringOrByteArrayOrStream. |
|
186 |
]. |
|
7042 | 187 |
|
188 |
^ hashStream hashValue |
|
7014 | 189 |
|
190 |
" |
|
191 |
MD5Stream hashValueOf:'BlaBlaBla' |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
192 |
MD5Stream hashValueOf:('makefile' asFilename readStream) |
7042 | 193 |
MD5Stream hashValueOf:('BlaBlaBla' readStream) |
7014 | 194 |
" |
17910 | 195 |
|
196 |
"Modified: / 12-01-2012 / 12:14:44 / cg" |
|
7014 | 197 |
! |
198 |
||
6864 | 199 |
hashValueOfFile:aFilename |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
200 |
|hash| |
7042 | 201 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
202 |
aFilename asFilename readingFileDo:[:readStream| |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
203 |
readStream binary. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
204 |
hash := self hashValueOf:readStream. |
7042 | 205 |
]. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
206 |
^ hash |
7014 | 207 |
|
208 |
" |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
209 |
MD5Stream hashValueOfFile:'makefile' |
7014 | 210 |
" |
6864 | 211 |
! ! |
212 |
||
213 |
!HashStream methodsFor:'accessing'! |
|
214 |
||
215 |
contents |
|
216 |
"return the entire contents of the stream |
|
217 |
- this is our hashValue." |
|
218 |
||
219 |
^ self hashValue |
|
220 |
||
221 |
"Created: / 17.3.1999 / 15:10:03 / stefan" |
|
222 |
! ! |
|
223 |
||
224 |
!HashStream methodsFor:'not implemented'! |
|
225 |
||
226 |
next |
|
17910 | 227 |
"I can only write" |
228 |
||
6864 | 229 |
^ self shouldNotImplement |
230 |
||
17910 | 231 |
"Created: / 17-03-1999 / 15:11:03 / stefan" |
232 |
"Modified (comment): / 09-01-2012 / 16:55:28 / cg" |
|
6864 | 233 |
! ! |
234 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
235 |
!HashStream methodsFor:'operations'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
236 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
237 |
digestMessage:bytes |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
238 |
"answer the digest of bytes" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
239 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
240 |
self reset. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
241 |
self nextPutAll:bytes. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
242 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
243 |
^ self contents. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
244 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
245 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
246 |
SHA1Stream new |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
247 |
digestMessage:'123456789abcdefg'; |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
248 |
digestMessage:'123456789abcdefg' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
249 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
250 |
(SHA1Stream new hmac key:'123456') |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
251 |
digestMessage:'123456789abcdefg'; |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
252 |
digestMessage:'123456789abcdefg' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
253 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
254 |
(SHA1Stream new hmac key:'123456') |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
255 |
nextPutAll:'123456789abcdefg'; |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
256 |
contents |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
257 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
258 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
259 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
260 |
hmac |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
261 |
"answer a hmac stream with myself" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
262 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
263 |
^ HmacStream on:self |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
264 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
265 |
" |
17910 | 266 |
(SHA1Stream new hmac key:'exampleKey') digestMessage:'message to generate MAC of' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
267 |
" |
17910 | 268 |
|
269 |
"Modified (comment): / 09-01-2012 / 13:51:01 / cg" |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
270 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
271 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
272 |
reset |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
273 |
"initialize to a clean state" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
274 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
275 |
^ self subclassResponsibility |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
276 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
277 |
|
6864 | 278 |
!HashStream methodsFor:'queries'! |
279 |
||
280 |
blockSize |
|
281 |
"the class knows about the basic block size" |
|
282 |
||
283 |
^ self class blockSize |
|
284 |
||
285 |
"Created: / 18.3.1999 / 10:17:02 / stefan" |
|
286 |
! |
|
287 |
||
288 |
hashSize |
|
17910 | 289 |
"return the size of the returned hashvalue (in bytes)" |
290 |
||
6864 | 291 |
"the class knows about the basic hash size" |
292 |
^ self class hashSize |
|
293 |
||
17910 | 294 |
"Created: / 18-03-1999 / 10:17:12 / stefan" |
295 |
"Modified: / 15-10-1999 / 11:53:20 / stefan" |
|
296 |
"Modified (comment): / 11-01-2012 / 10:12:09 / cg" |
|
6864 | 297 |
! |
298 |
||
7251 | 299 |
hashValue |
300 |
"retunr the value of the computeted hash" |
|
301 |
||
302 |
^ self subclassResponsibility |
|
303 |
! |
|
304 |
||
6864 | 305 |
isReadable |
306 |
"return true, if reading is supported by the recevier. |
|
307 |
Always return false here" |
|
308 |
||
309 |
^ false |
|
310 |
||
311 |
"Modified: / 17.3.1999 / 15:06:09 / stefan" |
|
312 |
! |
|
313 |
||
314 |
isWritable |
|
315 |
"return true, if writing is supported by the recevier. |
|
316 |
Always return true here" |
|
317 |
||
318 |
^ true |
|
319 |
||
320 |
"Created: / 17.3.1999 / 15:05:49 / stefan" |
|
321 |
! ! |
|
322 |
||
323 |
!HashStream methodsFor:'testing'! |
|
324 |
||
325 |
atEnd |
|
326 |
"return true if the end of the stream has been reached; |
|
327 |
this is never reached" |
|
328 |
||
329 |
^ false |
|
330 |
||
331 |
"Created: / 17.3.1999 / 15:08:55 / stefan" |
|
332 |
! ! |
|
333 |
||
334 |
!HashStream methodsFor:'writing'! |
|
335 |
||
7042 | 336 |
nextPut:anObject |
337 |
"add the hash of anObject to the computed hash so far. |
|
17910 | 338 |
anObject can be a Character, SmallInteger ByteArray or String" |
339 |
||
340 |
anObject isByteCollection ifTrue:[ |
|
341 |
self nextPutBytes:(anObject byteSize) from:anObject startingAt:1. |
|
342 |
^ self. |
|
343 |
]. |
|
7042 | 344 |
|
17910 | 345 |
anObject isCharacter ifTrue:[ |
346 |
"/ only ascii allowed !! |
|
347 |
self nextPutBytes:(ByteArray with:anObject codePoint). |
|
348 |
^ self. |
|
349 |
]. |
|
350 |
||
351 |
anObject isInteger ifTrue:[ |
|
352 |
"/ only 0..255 allowed !! |
|
353 |
anObject < 256 ifTrue:[ |
|
354 |
self nextPutAll:(ByteArray with:anObject). |
|
355 |
^ self. |
|
356 |
]. |
|
357 |
]. |
|
358 |
||
359 |
self error:'unsupported argument'. |
|
360 |
||
361 |
"Modified (comment): / 09-01-2012 / 16:54:05 / cg" |
|
7042 | 362 |
! |
363 |
||
6864 | 364 |
nextPutAll:aCollection |
365 |
"Hash streams handle Strings and ByteArrays in nextPut:" |
|
366 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
367 |
aCollection isByteCollection ifTrue:[ |
17910 | 368 |
self nextPutBytes:(aCollection byteSize) from:aCollection startingAt:1. |
6864 | 369 |
] ifFalse:[ |
370 |
super nextPutAll:aCollection |
|
371 |
]. |
|
372 |
||
17910 | 373 |
"Created: / 14-10-1999 / 11:22:50 / stefan" |
374 |
"Modified: / 09-01-2012 / 13:02:44 / cg" |
|
7042 | 375 |
! |
376 |
||
377 |
nextPutBytes:count from:anObject startingAt:start |
|
378 |
"write count bytes from an object starting at index start. |
|
379 |
Return the number of bytes written. |
|
380 |
The object must have non-pointer indexed instvars |
|
17910 | 381 |
(i.e. be a ByteArray, String, Float- or DoubleArray)." |
7042 | 382 |
|
17910 | 383 |
self subclassResponsibility |
7042 | 384 |
|
17910 | 385 |
"Modified: / 09-01-2012 / 16:41:31 / cg" |
6864 | 386 |
! ! |
387 |
||
388 |
!HashStream class methodsFor:'documentation'! |
|
389 |
||
390 |
version |
|
17910 | 391 |
^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.24 2012/01/12 11:25:28 cg Exp $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
392 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
393 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
394 |
version_CVS |
17910 | 395 |
^ 'Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.24 2012/01/12 11:25:28 cg Exp ' |
17865 | 396 |
! |
397 |
||
398 |
version_SVN |
|
17910 | 399 |
^ '$Id: HashStream.st 10758 2012-01-19 10:06:02Z vranyj1 $' |
17846 | 400 |
! ! |
17892 | 401 |
|
17909 | 402 |
|
17910 | 403 |