@@ -54,6 +54,7 @@ fn (nid Nid) str() string {
5454 }
5555}
5656
57+ // CurveOptions represents configuration options to drive keypair generation.
5758@[params]
5859pub struct CurveOptions {
5960pub mut :
@@ -94,7 +95,7 @@ enum KeyFlag {
9495}
9596
9697// generate_key generates a new key pair. If opt was not provided, its default to prime256v1 curve.
97- // If you want another curve, use in the following manner: `pubkey, pivkey := ecdsa.generate_key(nid: .secp384r1)!`
98+ // If you want another curve, use `pubkey, pivkey := ecdsa.generate_key(nid: .secp384r1)!` instead.
9899pub fn generate_key (opt CurveOptions) ! (PublicKey, PrivateKey) {
99100 // This can be simplified to just more simpler one
100101 pv := PrivateKey.new (opt)!
@@ -111,7 +112,7 @@ pub fn generate_key(opt CurveOptions) !(PublicKey, PrivateKey) {
111112// You should make sure, the seed bytes come from a cryptographically secure random generator,
112113// likes the `crypto.rand` or other trusted sources.
113114// Internally, the seed size's would be checked to not exceed the key size of underlying curve,
114- // ie, 32 bytes length for p-256 and secp256k1, 48 bytes length for p-384 and 64 bytes length for p-521.
115+ // ie, 32 bytes length for p-256 and secp256k1, 48 bytes length for p-384 and 66 bytes length for p-521.
115116// Its recommended to use seed with bytes length matching with underlying curve key size.
116117pub fn new_key_from_seed (seed []u8 , opt CurveOptions) ! PrivateKey {
117118 // Early exit check
@@ -276,9 +277,6 @@ pub fn (pv PrivateKey) seed() ![]u8 {
276277
277278// public_key gets the PublicKey from private key.
278279pub fn (pv PrivateKey) public_key () ! PublicKey {
279- // Check if EVP_PKEY opaque was availables or not.
280- // TODO: removes this check when its ready
281-
282280 bo := C.BIO_new (C.BIO_s_mem ())
283281 n := C.i2d_PUBKEY_bio (bo, pv.evpkey)
284282 assert n != 0
@@ -292,17 +290,13 @@ pub fn (pv PrivateKey) public_key() !PublicKey {
292290 }
293291}
294292
295- // equal compares two private keys was equal. Its checks for two things, ie:
296- //
297- // - whether both of private keys lives under the same group (curve),
298- // - compares if two private key bytes was equal.
293+ // equal compares two private keys was equal.
299294pub fn (priv_key PrivateKey) equal (other PrivateKey) bool {
300295 eq := C.EVP_PKEY_eq (voidptr (priv_key.evpkey), voidptr (other.evpkey))
301296 return eq == 1
302297}
303298
304- // free clears out allocated memory for PrivateKey
305- // Dont use PrivateKey after calling `.free()`
299+ // free clears out allocated memory for PrivateKey. Dont use PrivateKey after calling `.free()`
306300pub fn (pv &PrivateKey) free () {
307301 C.EVP_PKEY_free (pv.evpkey)
308302}
@@ -321,14 +315,13 @@ pub fn (pb PublicKey) verify(message []u8, sig []u8, opt SignerOpts) !bool {
321315 return verify_signature (pb.evpkey, sig, digest)
322316}
323317
324- // Compare two public keys
318+ // equal compares two public keys was equal.
325319pub fn (pub_key PublicKey) equal (other PublicKey) bool {
326320 eq := C.EVP_PKEY_eq (voidptr (pub_key.evpkey), voidptr (other.evpkey))
327321 return eq == 1
328322}
329323
330- // free clears out allocated memory for PublicKey.
331- // Dont use PublicKey after calling `.free()`
324+ // free clears out allocated memory for PublicKey. Dont use PublicKey after calling `.free()`
332325pub fn (pb &PublicKey) free () {
333326 C.EVP_PKEY_free (pb.evpkey)
334327}
0 commit comments