HashStream.st
branchjv
changeset 19167 699eef1bc815
parent 18120 e3a375d5f6a8
parent 19165 87e7d17b96e1
child 19412 1e842c25e51e
equal deleted inserted replaced
19158:cdce727939ab 19167:699eef1bc815
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
    13 
    15 
    14 Stream subclass:#HashStream
    16 Stream subclass:#HashStream
    15 	instanceVariableNames:''
    17 	instanceVariableNames:''
    16 	classVariableNames:''
    18 	classVariableNames:''
    17 	poolDictionaries:''
    19 	poolDictionaries:''
   268     ^ self hashValue
   270     ^ self hashValue
   269 
   271 
   270     "Created: / 17.3.1999 / 15:10:03 / stefan"
   272     "Created: / 17.3.1999 / 15:10:03 / stefan"
   271 ! !
   273 ! !
   272 
   274 
       
   275 !HashStream methodsFor:'compatibility - squeak'!
       
   276 
       
   277 digestMessage:bytes
       
   278     "SQUEAK: answer the digest of bytes"
       
   279 
       
   280     ^ self hashValueOf:bytes
       
   281 ! !
       
   282 
   273 !HashStream methodsFor:'not implemented'!
   283 !HashStream methodsFor:'not implemented'!
   274 
   284 
   275 next
   285 next
   276     "I can only write"
   286     "I can only write"
   277 
   287 
   281     "Modified (comment): / 09-01-2012 / 16:55:28 / cg"
   291     "Modified (comment): / 09-01-2012 / 16:55:28 / cg"
   282 ! !
   292 ! !
   283 
   293 
   284 !HashStream methodsFor:'operations'!
   294 !HashStream methodsFor:'operations'!
   285 
   295 
   286 digestMessage:bytes
   296 hashValueOf:bytes
   287     "answer the digest of bytes"
   297     "answer the digest of bytes"
   288 
   298 
   289     self reset.
   299     ^ self 
   290     self nextPutAll:bytes.
   300         reset;
   291 
   301         nextPutAll:bytes;
   292     ^ self hashValue.
   302         hashValue.
   293 
   303 
   294     "
   304     "
   295         SHA1Stream new 
   305         SHA1Stream new 
   296                 digestMessage:'123456789abcdefg';
   306                 hashValueOf:'123456789abcdefg';
   297                 digestMessage:'123456789abcdefg'
   307                 hashValueOf:'123456789abcdefg'
   298 
   308 
   299         (SHA1Stream new hmac key:'123456') 
   309         (SHA1Stream new hmac key:'123456') 
   300                 digestMessage:'123456789abcdefg';
   310                 hashValueOf:'123456789abcdefg';
   301                 digestMessage:'123456789abcdefg'
   311                 hashValueOf:'123456789abcdefg'
   302 
   312 
   303         (SHA1Stream new hmac key:'123456') 
   313         (SHA1Stream new hmac key:'123456') 
   304                 nextPutAll:'123456789abcdefg';
   314                 nextPutAll:'123456789abcdefg';
   305                 contents
   315                 contents
   306     "
   316     "
   345     ^ self subclassResponsibility
   355     ^ self subclassResponsibility
   346 
   356 
   347     "Modified (comment): / 23-01-2012 / 10:01:20 / cg"
   357     "Modified (comment): / 23-01-2012 / 10:01:20 / cg"
   348 !
   358 !
   349 
   359 
   350 hashValueOf:aString
       
   351     "for convenience:
       
   352      return the value of the computed hash of aString"
       
   353 
       
   354     self reset.
       
   355     self nextPutAll:aString.
       
   356     ^ self hashValue
       
   357 
       
   358     "Created: / 18-01-2012 / 17:26:25 / cg"
       
   359 !
       
   360 
       
   361 isReadable
   360 isReadable
   362     "return true, if reading is supported by the recevier.
   361     "return true, if reading is supported by the recevier.
   363      Always return false here"
   362      Always return false here"
   364 
   363 
   365     ^ false
   364     ^ false
   413 
   412 
   414     "Modified (comment): / 09-01-2012 / 16:54:05 / cg"
   413     "Modified (comment): / 09-01-2012 / 16:54:05 / cg"
   415 !
   414 !
   416 
   415 
   417 nextPutAll:aCollection
   416 nextPutAll:aCollection
   418     "Hash streams handle Strings and ByteArrays in nextPut:"
   417     "Hash streams handle Strings and ByteArrays in #nextPutBytes:"
   419 
   418 
   420     aCollection isByteCollection ifTrue:[
   419     aCollection isByteCollection ifTrue:[
   421         self nextPutBytes:(aCollection byteSize) from:aCollection startingAt:1.
   420         self nextPutBytes:(aCollection byteSize) from:aCollection startingAt:1.
   422     ] ifFalse:[
   421     ] ifFalse:[
   423         super nextPutAll:aCollection
   422         super nextPutAll:aCollection
   424     ].
   423     ].
   425 
   424 
   426     "Created: / 14-10-1999 / 11:22:50 / stefan"
   425     "Created: / 14-10-1999 / 11:22:50 / stefan"
   427     "Modified: / 09-01-2012 / 13:02:44 / cg"
   426     "Modified: / 09-01-2012 / 13:02:44 / cg"
       
   427 !
       
   428 
       
   429 nextPutByte:aByte
       
   430     "add the hash of anObject to the computed hash so far.
       
   431      aByte can be a SmallInteger <= 255"
       
   432 
       
   433     self nextPutBytes:1 from:(ByteArray with:aByte) startingAt:1.
   428 !
   434 !
   429 
   435 
   430 nextPutBytes:count from:anObject startingAt:start
   436 nextPutBytes:count from:anObject startingAt:start
   431     "write count bytes from an object starting at index start.
   437     "write count bytes from an object starting at index start.
   432      Return the number of bytes written.
   438      Return the number of bytes written.
   439 ! !
   445 ! !
   440 
   446 
   441 !HashStream class methodsFor:'documentation'!
   447 !HashStream class methodsFor:'documentation'!
   442 
   448 
   443 version
   449 version
   444     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.30 2014-10-02 17:48:04 stefan Exp $'
   450     ^ '$Header$'
   445 !
   451 !
   446 
   452 
   447 version_CVS
   453 version_CVS
   448     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.30 2014-10-02 17:48:04 stefan Exp $'
   454     ^ '$Header$'
   449 ! !
   455 ! !
   450 
   456