| 113 | |
| 114 | |
| 115 | AString 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 |
no outgoing calls
no test coverage detected