local myopenssl = require 'myopenssl'

assert(not pcall(myopenssl.get_digest, 'xyz'))

local sha256 = myopenssl.get_digest 'sha256'

assert(
    '\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23\z
     \xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad'
    ==
    sha256:digest 'abc'
)

assert(
    '\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\z
     \x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7'
    ==
    sha256:hmac('Hi There', '\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b')
)

assert(not pcall(myopenssl.read_raw, myopenssl.types.EVP_PKEY_X25519, true, ''))

local priv_key_raw =
    "\x40\x37\xf1\x1e\x67\xe1\x8d\x2a\x01\x31\x25\x7d\x7a\xc5\x43\xe3\z
     \x17\xed\x6a\x92\xe7\x90\xe0\xc1\x55\x8d\xe8\xdc\x24\xfa\xbd\x5a"
local pub_key_raw =
    "\xc8\x5b\x24\x85\x07\x76\x25\x69\x36\x2f\x93\x2c\x2f\x29\xaf\x22\z
     \xa5\x03\x4c\xc4\xcb\xb3\x90\x4e\x27\xd3\xe5\x5b\xbd\x05\x9a\x7c"
local priv_key = myopenssl.read_raw(myopenssl.types.EVP_PKEY_X25519, true, priv_key_raw)
assert(priv_key:export().pub == pub_key_raw)

local pem = io.open('test/rsa.pem'):read('a')
local priv = myopenssl.read_pem(pem, true)
priv:sign('a message') -- just make sure it doesn't blow up

pem = io.open('test/encrsa.pem'):read('a')
myopenssl.read_pem(pem, true, 'password')

print 'ok'
