MCPcopy Create free account
hub / github.com/cuberite/cuberite / GetPubKeyDER

Method GetPubKeyDER

src/Crypto.cpp:115–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114
115AString cRSAPrivateKey::GetPubKeyDER(void)
116{
117 class cPubKey
118 {
119 public:
120 cPubKey(rsa_context * a_Rsa) :
121 m_IsValid(false)
122 {
123 pk_init(&m_Key);
124 if (pk_init_ctx(&m_Key, pk_info_from_type(POLARSSL_PK_RSA)) != 0)
125 {
126 ASSERT(!"Cannot init PrivKey context");
127 return;
128 }
129 if (rsa_copy(pk_rsa(m_Key), a_Rsa) != 0)
130 {
131 ASSERT(!"Cannot copy PrivKey to PK context");
132 return;
133 }
134 m_IsValid = true;
135 }
136
137 ~cPubKey()
138 {
139 if (m_IsValid)
140 {
141 pk_free(&m_Key);
142 }
143 }
144
145 operator pk_context * (void) { return &m_Key; }
146
147 protected:
148 bool m_IsValid;
149 pk_context m_Key;
150 } PkCtx(&m_Rsa);
151
152 unsigned char buf[3000];
153 int res = pk_write_pubkey_der(PkCtx, buf, sizeof(buf));
154 if (res < 0)
155 {
156 return AString();
157 }
158 return AString((const char *)(buf + sizeof(buf) - res), (size_t)res);
159}
160
161
162

Callers 2

PrepareKeysMethod · 0.80
InitMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected