mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Python 3 fixes :)
This commit is contained in:
parent
bad5582632
commit
76c9006ed3
3 changed files with 11 additions and 6 deletions
|
@ -9,13 +9,12 @@ import base64
|
|||
|
||||
|
||||
def make_key(password):
|
||||
if type(password) is unicode:
|
||||
password = password.encode('utf-8')
|
||||
password = util.bytes(password)
|
||||
kdf = PBKDF2HMAC(
|
||||
algorithm=hashes.SHA256(),
|
||||
length=32,
|
||||
# Salt is hard-coded
|
||||
salt='\xf2\xd5q\x0e\xc1\x8d.\xde\xdc\x8e6t\x89\x04\xce\xf8',
|
||||
salt=b'\xf2\xd5q\x0e\xc1\x8d.\xde\xdc\x8e6t\x89\x04\xce\xf8',
|
||||
iterations=100000,
|
||||
backend=default_backend()
|
||||
)
|
||||
|
@ -34,7 +33,7 @@ class EncryptedJournal(Journal.Journal):
|
|||
and otherwise ask the user to enter a password up to three times.
|
||||
If the password is provided but wrong (or corrupt), this will simply
|
||||
return None."""
|
||||
with open(filename) as f:
|
||||
with open(filename, 'rb') as f:
|
||||
journal_encrypted = f.read()
|
||||
|
||||
def validate_password(password):
|
||||
|
|
|
@ -13,7 +13,6 @@ from . import util
|
|||
from . import install
|
||||
from . import plugins
|
||||
import jrnl
|
||||
import os
|
||||
import argparse
|
||||
import sys
|
||||
import logging
|
||||
|
|
|
@ -75,10 +75,17 @@ def u(s):
|
|||
|
||||
|
||||
def py2encode(s):
|
||||
"""Encode in Python 2, but not in python 3."""
|
||||
"""Encodes to UTF-8 in Python 2 but not r."""
|
||||
return s.encode("utf-8") if PY2 and type(s) is unicode else s
|
||||
|
||||
|
||||
def bytes(s):
|
||||
"""Returns bytes, no matter what."""
|
||||
if PY3:
|
||||
return s.encode("utf-8") if type(s) is not bytes else s
|
||||
return s.encode("utf-8") if type(s) is unicode else s
|
||||
|
||||
|
||||
def prnt(s):
|
||||
"""Encode and print a string"""
|
||||
STDOUT.write(u(s + "\n"))
|
||||
|
|
Loading…
Add table
Reference in a new issue