- if o in ('-c', '--cipher'):
- cipher = a
- elif o in ('-m', '--mac'):
- mac = a
- elif o in ('-h', '--hash'):
- hash = a
- else:
- raise 'Barf!'
- if len(args) > 2:
- return 1
- if len(args) >= 1:
- tag = args[0]
- else:
- tag = 'pwsafe'
-
- ## Choose a passphrase, and generate master keys.
- pp = C.ppread(tag, C.PMODE_VERIFY)
- if not mac: mac = hash + '-hmac'
- c = C.gcciphers[cipher]
- h = C.gchashes[hash]
- m = C.gcmacs[mac]
- ppk = PW.PPK(pp, c, h, m)
- ck = C.rand.block(c.keysz.default)
- mk = C.rand.block(m.keysz.default)
- k = Crypto(c, h, m, ck, mk)
-
- ## Set up the database, storing the basic information we need.
- db = G.open(file, 'n', 0600)
- db['tag'] = tag
- db['salt'] = ppk.salt
- db['cipher'] = cipher
- db['hash'] = hash
- db['mac'] = mac
- db['key'] = ppk.encrypt(wrapstr(ck) + wrapstr(mk))
- db['magic'] = k.encrypt(C.rand.block(h.hashsz))
+ if o in ('-c', '--cipher'): cipher = a
+ elif o in ('-m', '--mac'): mac = a
+ elif o in ('-h', '--hash'): hash = a
+ elif o in ('-d', '--database'): dbty = a
+ else: raise Exception("barf")
+ if len(args) > 2: return 1
+ if len(args) >= 1: tag = args[0]
+ else: tag = 'pwsafe'
+
+ ## Set up the database.
+ if mac is None: mac = hash + '-hmac'
+ try: dbcls = StorageBackend.byname(dbty)
+ except KeyError: die("Unknown database backend `%s'" % dbty)
+ PW.create(dbcls, file, tag,
+ C.gcciphers[cipher], C.gchashes[hash], C.gcmacs[mac])