-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To build demos, run `cmake .. -DENABLE_DEMOS=ON`
- Loading branch information
Showing
84 changed files
with
3,129 additions
and
863 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <gmssl/oid.h> | ||
#include <gmssl/asn1.h> | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
int ret = -1; | ||
uint8_t der[] = { 0x06,0x06,0x2a,0x81,0x1c,0xcf,0x55,0x01 }; | ||
uint32_t oid[32]; | ||
size_t oid_num; | ||
const uint8_t *cp; | ||
size_t len; | ||
size_t i; | ||
|
||
cp = der; | ||
len = sizeof(der); | ||
if (asn1_object_identifier_from_der(oid, &oid_num, &cp, &len) != 1) { | ||
fprintf(stderr, "asn1_object_identifier_from_der() error\n"); | ||
goto err; | ||
} | ||
|
||
printf("oid: "); | ||
for (i = 0; i < oid_num; i++) { | ||
printf("%u ", oid[i]); | ||
} | ||
printf("\n"); | ||
|
||
ret = 0; | ||
err: | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <gmssl/oid.h> | ||
#include <gmssl/asn1.h> | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
int ret = -1; | ||
uint32_t oid[] = {1,2,156,10197,1}; | ||
uint8_t buf[64]; | ||
uint8_t *p; | ||
size_t len; | ||
size_t i; | ||
|
||
p = buf; | ||
len = 0; | ||
if (asn1_object_identifier_to_der(oid, sizeof(oid)/sizeof(oid[0]), &p, &len) != 1) { | ||
fprintf(stderr, "asn1_object_identifier_to_der() error\n"); | ||
goto err; | ||
} | ||
|
||
printf("oid: "); | ||
for (i = 0; i < sizeof(oid)/sizeof(oid[0]); i++) { | ||
printf("%u ", oid[i]); | ||
} | ||
printf("\n"); | ||
|
||
printf("der: "); | ||
for (i = 0; i < len; i++) { | ||
printf("%02x ", buf[i]); | ||
} | ||
printf("\n"); | ||
|
||
ret = 0; | ||
err: | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <gmssl/base64.h> | ||
#include <gmssl/error.h> | ||
#include <gmssl/rand.h> | ||
|
||
int main(void) | ||
{ | ||
BASE64_CTX ctx; | ||
|
||
uint8_t buf[200]; | ||
char base64[400] = {0}; | ||
uint8_t *in = buf; | ||
uint8_t *out = (uint8_t *)base64; | ||
int len; | ||
int i; | ||
int inlen = 47; | ||
|
||
rand_bytes(buf, sizeof(buf)); | ||
|
||
base64_encode_init(&ctx); | ||
|
||
base64_encode_update(&ctx, in, inlen, out, &len); | ||
out += len; | ||
in += inlen; | ||
printf("1 %s\n", base64); | ||
|
||
base64_encode_update(&ctx, in, inlen, out, &len); | ||
out += len; | ||
in += inlen; | ||
printf("2 %s\n", base64); | ||
|
||
base64_encode_update(&ctx, in, 30, out, &len); | ||
out += len; | ||
in += 48; | ||
printf("3 %s\n", base64); | ||
|
||
base64_encode_update(&ctx, in, 30, out, &len); | ||
out += len; | ||
in += 48; | ||
printf("4 %s\n", base64); | ||
|
||
return 0; | ||
|
||
} |
Oops, something went wrong.