(module idcheck-db mzscheme
(require (lib "contract.ss")
(file "base.ss")
(file "idcheck-util.ss"))
(provide/contract
[add-user! (-> string? string? any)]
[remove-user! (-> string? any)]
[lookup-user (-> string? (or/c string? false/c))]
[get-username (-> string? string?)])
(define db (make-hash-table 'equal))
(define (add-user! key data)
(hash-table-put!
db
(key->number/fail key)
data))
(define (remove-user! key)
(hash-table-remove!
db
(key->number/fail key)))
(define (lookup-user key)
(hash-table-get
db
(key->number/fail key)
(lambda ()
#f)))
(define (get-username str)
(let ([port (open-input-string str)])
(read-line port 'any)
(read-line port 'any)))
(define (key->number/fail str)
(if (registered-key? str)
(string->number str)
(raise-exn:idcheck
(format "The string ~a is not a valid IDCheck key" str))))
)