Accept passphrases as bytes
The OpenPGP specifications are ambiguous about the encoding of passwords. In practice, we expect most passphrases to be UTF-8-encoded, but if the incoming passphrase is in fact a bytestring, we ought to be able to handle it correctly. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
This commit is contained in:
@@ -1023,8 +1023,10 @@ class String2Key(Field):
|
||||
|
||||
# Simple S2K - always done
|
||||
hsalt = b''
|
||||
##TODO: we could accept a passphrase that is optionally already `bytes`
|
||||
hpass = passphrase.encode('utf-8')
|
||||
if isinstance(passphrase, bytes):
|
||||
hpass = passphrase
|
||||
else:
|
||||
hpass = passphrase.encode('utf-8')
|
||||
|
||||
# salted, iterated S2K
|
||||
if self.specifier >= String2KeyType.Salted:
|
||||
|
||||
Reference in New Issue
Block a user