Plaster
New
List
Login
common-lisp
default
anonymous
2021.02.15 14:32:19
size_t olm_pickle_account( OlmAccount * account, void const * key, size_t key_length, void * pickled, size_t pickled_length ); (defmethod pickle ((account account) (passphrase string)) "Store an Olm account. Stores an account as a base64 string. Encrypts the account using the supplied passphrase. Returns a byte object containing the base64 encoded string of the pickled account. Signals 'olm-account-error on failure." (let* ((p-length (%olm:pickle-account-length (account account))) (pass-bytes (ironclad:ascii-string-to-byte-array passphrase)) (pass-vec (static-vectors:make-static-vector (length passphrase) :initial-contents pass-bytes)) (p-buffer (make-string p-length))) (%olm:pickle-account (account account) (static-vectors:static-vector-pointer pass-vec) (length pass-bytes) p-buffer p-length) (check-error account) (dotimes (i (length pass-bytes)) (setf (aref pass-bytes i) #\Nul)) p-length))
Raw
Annotate
Repaste
Edit
Annotations
common-lisp
default
anonymous
2021.02.15 14:56:19
;;;size_t olm_pickle_account( ;;; OlmAccount * account, //input value ;;; void const * key, size_t key_length, //input value ;;; void * pickled, size_t pickled_length //output value ;;;); (defmethod pickle ((account account) (passphrase string)) "Store an Olm account. Stores an account as a base64 string. Encrypts the account using the supplied passphrase. Returns a byte object containing the base64 encoded string of the pickled account. Signals 'olm-account-error on failure." (let* ((p-length (%olm:pickle-account-length (account account)))) ;; For safety one should probably bind ;; cffi:*default-foreign-encoding* here as the next two with- ;; macros rely on it. The default of utf-8 should be fine though. (cffi:with-foreign-string ((foreign-key foreign-key-length) passphrase) ;; This stack allocates. If p-size can be large, then you'll ;; need to do an unwind-protect, allocate, free either in your ;; own macro or manually. (unwind-protect (cffi:with-foreign-pointer-as-string (p-buffer p-length) (%olm:pickle-account (account account) ;I'm assuming this is correct already? foreign-key foreign-key-length p-buffer p-length)) (loop for i from 0 below foreign-key-length do (setf (cffi:mem-aref foreign-key :uint8 i) 0))))))
Raw
Repaste
Edit