mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 12:33:39 +08:00
Refactor X509_KEY
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/sm2.h>
|
||||
#include <gmssl/ec.h>
|
||||
#include <gmssl/error.h>
|
||||
|
||||
@@ -61,58 +60,9 @@ static int test_ec_named_curve(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int test_ec_point_print(void)
|
||||
{
|
||||
SM2_KEY sm2_key;
|
||||
uint8_t buf[256];
|
||||
uint8_t *p = buf;
|
||||
size_t len = 0;
|
||||
|
||||
if (sm2_key_generate(&sm2_key) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (sm2_z256_point_to_der(&(sm2_key.public_key), &p, &len) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
ec_point_print(stderr, 0, 4, "ECPoint", buf, len);
|
||||
|
||||
printf("%s() ok\n", __FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int test_ec_private_key_print(void)
|
||||
{
|
||||
SM2_KEY sm2_key;
|
||||
uint8_t buf[256];
|
||||
uint8_t *p = buf;
|
||||
const uint8_t *cp = buf;
|
||||
size_t len = 0;
|
||||
const uint8_t *d;
|
||||
size_t dlen;
|
||||
|
||||
if (sm2_key_generate(&sm2_key) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (sm2_private_key_to_der(&sm2_key, &p, &len) != 1
|
||||
|| asn1_sequence_from_der(&d, &dlen, &cp, &len) != 1
|
||||
|| asn1_length_is_zero(len) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
ec_private_key_print(stderr, 0, 4, "ECPrivateKey", d, dlen);
|
||||
|
||||
printf("%s() ok\n", __FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (test_ec_named_curve() != 1) goto err;
|
||||
if (test_ec_point_print() != 1) goto err;
|
||||
if (test_ec_private_key_print() != 1) goto err;
|
||||
printf("%s all tests passed\n", __FILE__);
|
||||
return 0;
|
||||
err:
|
||||
|
||||
Reference in New Issue
Block a user