# Path: typtop/pw_pkcrypto.py



from typtop.pw_pkcrypto import (
    generate_key_pair, pkencrypt, pkdecrypt,
    encrypt, decrypt, hmac256, compute_id,
    serialize_pk, serialize_sk, deserialize_sk,
    deserialize_pk, verify_pk_sk, harden_pw, verify,
    pwencrypt, pwdecrypt, pad_pw, unpad_pw
)
from base64 import urlsafe_b64encode, urlsafe_b64decode
import struct
import os
import pytest
        assert unpad_pw(padded_pw, pdlen) == pw[:pdlen]

def test_fail_pkencrypt():
    m = 'asdfasdfsadfasdfasdfasdfasdfasdfasd'
    pk, sk = generate_key_pair()
    c = pkencrypt(pk, m).split('||')
    cprime = pkencrypt(pk, m + '1').split('||')
    assert len(c) == 2 and len(cprime) == 2
    c = c[0] + '||' + cprime[1]
    assert pkdecrypt(sk, '||'.join(cprime)) == m + '1'
    with pytest.raises(ValueError) as excinfo:
        pkdecrypt(sk, c)
        print(excinfo)

def test_symencrypt():
    msgs = [
        'aflashdfhaasdfadsf',
        'asdfkjashdflkashld'[:16],
        'The best secret message ever written by any human!!'
    ]
    k = os.urandom(16)
    for m in msgs:
        c = encrypt(k, m)
        assert decrypt(k, c) == m

def test_compute_id():
    pw = 'asdadf'
    sa = '0'*16
    t1 = compute_id(sa, pw)
    t2 = hmac256(sa, pw)

# Path: typtop/pw_pkcrypto.py



# Path: tests/test_pw_pkcrypto2.py
from typtop.pw_pkcrypto import (
    generate_key_pair, pkencrypt, pkdecrypt,
    encrypt, decrypt, hmac256, compute_id,
    serialize_pk, serialize_sk, deserialize_sk,
    deserialize_pk, verify_pk_sk, harden_pw, verify,
    pwencrypt, pwdecrypt, pad_pw, unpad_pw
)
from base64 import urlsafe_b64encode, urlsafe_b64decode
import struct
import os
import pytest

        assert unpad_pw(padded_pw, pdlen) == pw[:pdlen]

def test_fail_pkencrypt():
    m = 'asdfasdfsadfasdfasdfasdfasdfasdfasd'
    pk, sk = generate_key_pair()
    c = pkencrypt(pk, m).split('||')
    cprime = pkencrypt(pk, m + '1').split('||')
    assert len(c) == 2 and len(cprime) == 2
    c = c[0] + '||' + cprime[1]
    assert pkdecrypt(sk, '||'.join(cprime)) == m + '1'
    with pytest.raises(ValueError) as excinfo:
        pkdecrypt(sk, c)
        print(excinfo)

def test_symencrypt():
    msgs = [
        'aflashdfhaasdfadsf',
        'asdfkjashdflkashld'[:16],
        'The best secret message ever written by any human!!'
    ]
    k = os.urandom(16)
    for m in msgs:
        c = encrypt(k, m)
        assert decrypt(k, c) == m

def test_compute_id():
    pw = 'asdadf'
    sa = '0'*16
    t1 = compute_id(sa, pw)
    t2 = hmac256(sa, pw)

    assert t1 == compute_id(sa, unicode(pw))