Esempio n. 1
0
def test_keypair_generate():
    """
    """
    keypair = bbclib.KeyPair()
    keypair.generate()
    assert (keypair.private_key_len.value == 32)
    assert (keypair.public_key_len.value == 65)
Esempio n. 2
0
def test_keypair_pubkey():
    """
    """
    keypair = bbclib.KeyPair(curvetype=bbclib.KeyType.ECDSA_SECP256k1,
                             privkey=in_privkey)
    keypair.mk_keyobj_from_private_key()
    assert (keypair.public_key_len.value == 65)
    assert (bytes(
        keypair.public_key)[:keypair.public_key_len.value] == in_pubkey)
Esempio n. 3
0
def test_keypair_pem():
    keypair = bbclib.KeyPair(curvetype=bbclib.KeyType.ECDSA_SECP256k1,
                             privkey=in_privkey,
                             pubkey=in_pubkey)

    pem = keypair.get_private_key_in_pem()
    assert (bytes(pem) == in_pem[:(len(in_pem) - 1)])  # ヌル終端を取り除いて比較する。

    keypair.mk_keyobj_from_private_key_pem(pem.decode())  # 文字列化する。
    assert (bytes(
        keypair.private_key)[:keypair.private_key_len.value] == in_privkey)
    assert (bytes(
        keypair.public_key)[:keypair.public_key_len.value] == in_pubkey)
Esempio n. 4
0
def test_keypair_der():
    """
    """
    keypair = bbclib.KeyPair(curvetype=bbclib.KeyType.ECDSA_SECP256k1,
                             privkey=in_privkey,
                             pubkey=in_pubkey)

    der = keypair.get_private_key_in_der()
    assert (der == in_der)

    keypair.mk_keyobj_from_private_key_der(der)
    assert (bytes(
        keypair.private_key)[:keypair.private_key_len.value] == in_privkey)
    assert (bytes(
        keypair.public_key)[:keypair.public_key_len.value] == in_pubkey)
Esempio n. 5
0
def test_keypair_sign_and_verify():
    """
    """
    digest = binascii.a2b_hex(
        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

    keypair = bbclib.KeyPair(curvetype=bbclib.KeyType.ECDSA_SECP256k1,
                             privkey=in_privkey,
                             pubkey=in_pubkey)
    signature = keypair.sign(digest)
    print("signature = {}".format(signature))

    ret = keypair.verify(digest, signature)
    # print("ret = {}".format(ret))
    assert (ret == 1)

    not_digest = binascii.a2b_hex("bbbbbb")

    ret = keypair.verify(not_digest, signature)
    # print("ret = {}".format(ret))
    assert (ret == 0)