MCPcopy Create free account
hub / github.com/apple/foundationdb / encodeKey

Function encodeKey

fdbrpc/JsonWebKeySet.cpp:662–688  ·  view source on GitHub ↗

Add exactly one object to context of writer. Object shall contain JWK-encoded public or private key

Source from the content-addressed store, hash-verified

660
661// Add exactly one object to context of writer. Object shall contain JWK-encoded public or private key
662bool encodeKey(rapidjson::Writer<rapidjson::StringBuffer>& writer, StringRef keyName, const PublicOrPrivateKey& key) {
663 auto const isPublic = key.isPublic();
664 auto pKey = std::add_pointer_t<EVP_PKEY>();
665 auto alg = PKeyAlgorithm{};
666 if (isPublic) {
667 auto const& keyObj = key.getPublic();
668 pKey = keyObj.nativeHandle();
669 alg = keyObj.algorithm();
670 } else {
671 auto const& keyObj = key.getPrivate();
672 pKey = key.getPrivate().nativeHandle();
673 alg = keyObj.algorithm();
674 }
675 if (!pKey) {
676 JWK_WRITE_ERROR("PKey object to encode is null");
677 return false;
678 }
679 if (alg == PKeyAlgorithm::EC) {
680 return encodeEcKey(writer, keyName, pKey, isPublic);
681 } else if (alg == PKeyAlgorithm::RSA) {
682 return encodeRsaKey(writer, keyName, pKey, isPublic);
683 } else {
684 JWK_WRITE_ERROR("Attempted to encode PKey with unsupported algorithm");
685 return false;
686 }
687 return true;
688}
689
690void testPublicKey(PrivateKey (*factory)()) {
691 // stringify-deserialize public key.

Callers 1

toStringRefMethod · 0.70

Calls 7

encodeEcKeyFunction · 0.85
encodeRsaKeyFunction · 0.85
getPublicMethod · 0.80
algorithmMethod · 0.80
getPrivateMethod · 0.80
isPublicMethod · 0.45
nativeHandleMethod · 0.45

Tested by

no test coverage detected