diff options
| author | 2023-05-11 10:48:37 +0200 | |
|---|---|---|
| committer | 2023-05-11 10:48:37 +0200 | |
| commit | 9c4e491497d42770d64e9770fe347514f577cf39 (patch) | |
| tree | 3be24fbb7e48e0fd1f86de6caadc671de8f30cc8 /xs_openssl.h | |
| parent | In /relationship, the id[] can be a list. (diff) | |
| download | penes-snac2-9c4e491497d42770d64e9770fe347514f577cf39.tar.gz penes-snac2-9c4e491497d42770d64e9770fe347514f577cf39.tar.xz penes-snac2-9c4e491497d42770d64e9770fe347514f577cf39.zip | |
Backport from xs.
Diffstat (limited to 'xs_openssl.h')
| -rw-r--r-- | xs_openssl.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/xs_openssl.h b/xs_openssl.h index eef57ed..4a86046 100644 --- a/xs_openssl.h +++ b/xs_openssl.h | |||
| @@ -22,6 +22,64 @@ int xs_evp_verify(const char *pubkey, const char *mem, int size, const char *b64 | |||
| 22 | #include "openssl/pem.h" | 22 | #include "openssl/pem.h" |
| 23 | #include "openssl/evp.h" | 23 | #include "openssl/evp.h" |
| 24 | 24 | ||
| 25 | #if 0 | ||
| 26 | xs_str *xs_base64_enc(const xs_val *data, int sz) | ||
| 27 | /* encodes data to base64 */ | ||
| 28 | { | ||
| 29 | BIO *mem, *b64; | ||
| 30 | BUF_MEM *bptr; | ||
| 31 | |||
| 32 | b64 = BIO_new(BIO_f_base64()); | ||
| 33 | mem = BIO_new(BIO_s_mem()); | ||
| 34 | b64 = BIO_push(b64, mem); | ||
| 35 | |||
| 36 | BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); | ||
| 37 | |||
| 38 | BIO_write(b64, data, sz); | ||
| 39 | BIO_flush(b64); | ||
| 40 | BIO_get_mem_ptr(b64, &bptr); | ||
| 41 | |||
| 42 | int n = bptr->length; | ||
| 43 | xs_str *s = xs_realloc(NULL, _xs_blk_size(n + 1)); | ||
| 44 | |||
| 45 | memcpy(s, bptr->data, n); | ||
| 46 | s[n] = '\0'; | ||
| 47 | |||
| 48 | BIO_free_all(b64); | ||
| 49 | |||
| 50 | return s; | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | xs_val *xs_base64_dec(const xs_str *data, int *size) | ||
| 55 | /* decodes data from base64 */ | ||
| 56 | { | ||
| 57 | BIO *b64, *mem; | ||
| 58 | |||
| 59 | *size = strlen(data); | ||
| 60 | |||
| 61 | b64 = BIO_new(BIO_f_base64()); | ||
| 62 | mem = BIO_new_mem_buf(data, *size); | ||
| 63 | b64 = BIO_push(b64, mem); | ||
| 64 | |||
| 65 | BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); | ||
| 66 | |||
| 67 | /* alloc a very big buffer */ | ||
| 68 | xs_str *s = xs_realloc(NULL, *size); | ||
| 69 | |||
| 70 | *size = BIO_read(b64, s, *size); | ||
| 71 | |||
| 72 | /* adjust to current size */ | ||
| 73 | s = xs_realloc(s, _xs_blk_size(*size + 1)); | ||
| 74 | s[*size] = '\0'; | ||
| 75 | |||
| 76 | BIO_free_all(mem); | ||
| 77 | |||
| 78 | return s; | ||
| 79 | } | ||
| 80 | #endif | ||
| 81 | |||
| 82 | |||
| 25 | xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex) | 83 | xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex) |
| 26 | /* generic function for generating and encoding digests */ | 84 | /* generic function for generating and encoding digests */ |
| 27 | { | 85 | { |