- "Calculate the MD5 message-digest of data in sequence. On CMU CL
-this works for all sequences whose element-type is supported by the
-underlying MD5 routines, on other implementations it only works for 1d
-simple-arrays with such element types."
- (declare (optimize (speed 3) (space 0) (debug 0))
- (type vector sequence) (type fixnum start))
- (let ((state (make-md5-state)))
- (declare (type md5-state state))
- #+cmu
- (lisp::with-array-data ((data sequence) (real-start start) (real-end end))
- (update-md5-state state data :start real-start :end real-end))
- #+sbcl
- (sb-kernel:with-array-data ((data sequence) (real-start start) (real-end end))
- (update-md5-state state data :start real-start :end real-end))
- #-(or cmu sbcl)
- (let ((real-end (or end (length sequence))))
- (declare (type fixnum real-end))
- (update-md5-state state sequence :start start :end real-end))
- (finalize-md5-state state)))
+ "Calculate the MD5 message-digest of data bounded by START and END
+in SEQUENCE , which must be a vector with element-type (UNSIGNED-BYTE
+8)."
+ (declare (optimize (speed 3) (safety 3) (space 0) (debug 1))
+ (type (vector (unsigned-byte 8)) sequence) (type fixnum start))
+ (locally
+ (declare (optimize (safety 1) (debug 0)))
+ (let ((state (make-md5-state)))
+ (declare (type md5-state state))
+ #+cmu
+ ;; respect the fill pointer
+ (let ((end (or end (length sequence))))
+ (lisp::with-array-data ((data sequence) (real-start start) (real-end end))
+ (declare (ignore real-end))
+ (update-md5-state state data :start real-start
+ :end (+ real-start (- end start)))))
+ #+sbcl
+ ;; respect the fill pointer
+ (let ((end (or end (length sequence))))
+ (sb-kernel:with-array-data ((data sequence)
+ (real-start start)
+ (real-end end)
+ :check-fill-pointer t)
+ (declare (ignore real-end))
+ (update-md5-state state data :start real-start
+ :end (+ real-start (- end start)))))
+ #-(or cmu sbcl)
+ (let ((real-end (or end (length sequence))))
+ (declare (type fixnum real-end))
+ (update-md5-state state sequence :start start :end real-end))
+ (finalize-md5-state state))))
+
+(defun md5sum-string (string &key (external-format :default) (start 0) end)
+ "Calculate the MD5 message-digest of the binary representation
+of STRING (as octets) in EXTERNAL-FORMAT. The boundaries START
+and END refer to character positions in the string, not to octets
+in the resulting binary representation."
+ (declare (optimize (speed 3) (safety 3) (space 0) (debug 1))
+ (type string string) (type fixnum start))
+ (locally
+ (declare (optimize (safety 1) (debug 0)))
+ (md5sum-sequence
+ (sb-ext:string-to-octets string
+ :external-format external-format
+ :start start :end end))))