[crypticl-cvs] CVS crypticl/src
tskogan
tskogan at common-lisp.net
Sat Jan 20 19:33:41 UTC 2007
Update of /project/crypticl/cvsroot/crypticl/src
In directory clnet:/tmp/cvs-serv4220/src
Modified Files:
utilities.lisp common.lisp
Log Message:
Replace the two last calls to Allegro specific excl: functions.
--- /project/crypticl/cvsroot/crypticl/src/utilities.lisp 2007/01/17 22:00:52 1.6
+++ /project/crypticl/cvsroot/crypticl/src/utilities.lisp 2007/01/20 19:33:41 1.7
@@ -35,13 +35,6 @@
(setq integer (+ (* integer 256) (aref vector i))))
integer))
-
-(defun string-to-octets (str &optional (start 0) (end (length str)))
- (let* ((size (- end start))
- (o (make-array size :element-type '(unsigned-byte 8))))
- (dotimes (i size o)
- (setf (aref o i) (char-code (char str (+ start i)))))))
-
(defun integer-to-octet-vector (integer &key vector (start 0))
"Transforms positive integers to byte vector using big endian format. Assumes a byte is 8 bits. "
(let* ((required-length
@@ -173,8 +166,8 @@
(dolist (s lst)
(write-string s str))))
-;;;;;;;
-;;; String utilities (from CLOCC)
+
+;;;; String utilities
(defun split-seq (seq pred &key (start 0) end key strict)
"Return a list of subseq's of SEQ, split on predicate PRED.
@@ -213,3 +206,22 @@
nil ; prefix longer than string
(string= s prefix :end1 len))))
+(defun string-to-octets (s)
+ "Return string to byte array.
+
+This function is NOT portable and very implementation dependend.
+Each character is converted to a single byte. Intended for working with
+ASCII strings and 8-bit encodings.
+"
+ (map '(simple-array (unsigned-byte 8))
+ ;; NB! char-code can return a number bigger than 8 bits
+ #'(lambda (c) (ldb (byte 8 0) (char-code c))) s))
+
+(defun octets-to-string (octet-vector)
+ "Convert byte array to string.
+
+Assumes the byte array was produced by string-to-octets on
+the same platform."
+ (map 'string #'code-char octet-vector))
+
+
\ No newline at end of file
--- /project/crypticl/cvsroot/crypticl/src/common.lisp 2007/01/20 15:37:51 1.9
+++ /project/crypticl/cvsroot/crypticl/src/common.lisp 2007/01/20 19:33:41 1.10
@@ -5,10 +5,10 @@
;;;; Author: Taale Skogan
;;;; Distribution: See the accompanying file LICENSE.
-;; To do:
-;;-register constructors for byte-encoding constructors in the same way as for normal constructors.
+;; TODO:
+;;-register constructors for byte-encoding constructors in the same way
+;; as for normal constructors.
;;-better spki string encoding with type.
-;;-replace excl function
(in-package crypticl)
@@ -153,7 +153,6 @@
nil)))
#'string-reader)))
-
(defun make-byte-array-reader-function-old (array &optional (end (length array)))
"Return a reader that for each call returns the next byte from the array or
nil if it reaches the end. Uses closure."
@@ -256,8 +255,7 @@
(defun get-element-encodings (msg-elements)
"Get byte encoding for each msg element, transform to base64 spki and return the bytes."
- ;;TODO replace excl function
- (excl:string-to-octets
+ (string-to-octets
(to-spki (mapcar #'get-msg-element-encoding msg-elements))))
(defun to-spki(msg-elements)
@@ -310,7 +308,7 @@
(octet-vector-to-integer octvec))
(t (error "Unknown type=~A" type))))
(parse-spki
- (excl:octets-to-string encoding))))
+ (octets-to-string encoding))))
;;;;;;
More information about the Crypticl-cvs
mailing list