Check: can db be read back before writing to disk? - pee - Pee a password manager;Pee - because you have to...
(HTM) git clone git://vernunftzentrum.de/pee.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 88416143f5476e68425e91b6f9dca81f74f837f4
(DIR) parent 1b06ec6f3c1ccdfb4c3bee842a122b22bdce556c
(HTM) Author: Christian Kellermann <ckeen@pestilenz.org>
Date: Tue, 12 Jan 2016 13:12:12 +0100
Check: can db be read back before writing to disk?
This at least protects the db from being destroyed should we
accidentally serialise an object that cannot be read in by read, such
as #<unspecified>.
Diffstat:
pee.scm | 9 +++++++++
1 file changed, 9 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/pee.scm b/pee.scm
@@ -123,7 +123,16 @@
(let ((content (with-input-from-file file read-all)))
(enc/dec-file content passphrase symmetric-unbox)))
+(define (check-content content)
+ (condition-case
+ (with-input-from-string
+ (with-output-to-string
+ (lambda () (pp content)))
+ read)
+ (e () (error "Internal error: Writing of unserialisable object detected."))))
+
(define (encrypt-file file content passphrase)
+ (check-content content)
(let ((cyphertext (enc/dec-file
(with-output-to-string (lambda () (pp content)))
passphrase