wahern / luaossl

Most comprehensive OpenSSL module in the Lua universe.

Home Page:http://25thandclement.com/~william/projects/luaossl.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add comparison operations for keys

daurnimator opened this issue · comments

Currenly to see if two key objects contain the same key I have to convert them to PEM and compare the strings.
Instead, it would be nice to have an __eq that uses EVP_PKEY_cmp_parameters.

EVP_PKEY_cmp_parameters doesn't work for all key types (notably RSA)
EVP_PKEY_cmp only checks the public keys match, not the private.

This doesn't seem to be possible without delving into each key type, so closing.

Useful test script:

#!/usr/bin/env lua

local pkey = require"openssl.pkey"

local a = pkey.new()
local b = pkey.new(a:toPEM("private"))
assert(a==b)
local c = pkey.new(a:toPEM("public"))
assert(a~=c)