| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/asn1.h> |
| 16 | #include <openssl/dsa.h> |
| 17 | #include <openssl/ec_key.h> |
| 18 | #include <openssl/err.h> |
| 19 | #include <openssl/evp.h> |
| 20 | #include <openssl/rsa.h> |
| 21 |
| 22 |
| 23 | int i2d_PrivateKey(const EVP_PKEY *a, uint8_t **pp) { |
| 24 | switch (EVP_PKEY_id(a)) { |
| 25 | case EVP_PKEY_RSA: |
| 26 | return i2d_RSAPrivateKey(EVP_PKEY_get0_RSA(a), pp); |
| 27 | case EVP_PKEY_EC: |
| 28 | return i2d_ECPrivateKey(EVP_PKEY_get0_EC_KEY(a), pp); |
| 29 | case EVP_PKEY_DSA: |
| 30 | return i2d_DSAPrivateKey(EVP_PKEY_get0_DSA(a), pp); |
| 31 | default: |
| 32 | // Although this file is in crypto/x509 for layering reasons, it emits |
| 33 | // an error code from ASN1 for OpenSSL compatibility. |
| 34 | OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
| 35 | return -1; |
| 36 | } |
| 37 | } |
| 38 |