Skip to content
File

Blob: src/workerd/api/crypto/ec.h

cpp51 lines
1#pragma once
2 
3#include "impl.h"
4#include "keys.h"
5 
6#include <openssl/base.h>
7 
8#include <kj/common.h>
9 
10namespace workerd::api {
11 
12class Ec final {
13 public:
14 static kj::Maybe<Ec> tryGetEc(const EVP_PKEY* key);
15 Ec(EC_KEY* key);
16 
17 inline const EC_KEY* getKey() {
18 return key;
19 }
20 inline const EC_GROUP* getGroup() const {
21 return group;
22 }
23 int getCurveName() const;
24 
25 const EC_POINT* getPublicKey() const;
26 const BIGNUM* getPrivateKey() const;
27 uint32_t getDegree() const;
28 
29 inline const BIGNUM& getX() const {
30 return *x;
31 }
32 inline const BIGNUM& getY() const {
33 return *y;
34 }
35 
36 SubtleCrypto::JsonWebKey toJwk(
37 KeyType keyType, kj::StringPtr curveName) const KJ_WARN_UNUSED_RESULT;
38 
39 jsg::JsArrayBuffer getRawPublicKey(jsg::Lock& js) const KJ_WARN_UNUSED_RESULT;
40 
41 CryptoKey::AsymmetricKeyDetails getAsymmetricKeyDetail(jsg::Lock& js) const;
42 
43 private:
44 EC_KEY* key;
45 const EC_GROUP* group = nullptr;
46 kj::Own<BIGNUM> x;
47 kj::Own<BIGNUM> y;
48};
49 
50} // namespace workerd::api