summaryrefslogtreecommitdiffstats
path: root/src/crypto/bytestring
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bytestring')
-rw-r--r--src/crypto/bytestring/CMakeLists.txt2
-rw-r--r--src/crypto/bytestring/bytestring_test.cc13
-rw-r--r--src/crypto/bytestring/cbb.c9
-rw-r--r--src/crypto/bytestring/cbs.c20
-rw-r--r--src/crypto/bytestring/internal.h8
5 files changed, 14 insertions, 38 deletions
diff --git a/src/crypto/bytestring/CMakeLists.txt b/src/crypto/bytestring/CMakeLists.txt
index 3462aee..cbbacf2 100644
--- a/src/crypto/bytestring/CMakeLists.txt
+++ b/src/crypto/bytestring/CMakeLists.txt
@@ -1,4 +1,4 @@
-include_directories(../../include)
+include_directories(. .. ../../include)
add_library(
bytestring
diff --git a/src/crypto/bytestring/bytestring_test.cc b/src/crypto/bytestring/bytestring_test.cc
index e987e1b..66e9c1e 100644
--- a/src/crypto/bytestring/bytestring_test.cc
+++ b/src/crypto/bytestring/bytestring_test.cc
@@ -109,7 +109,7 @@ static bool TestGetASN1() {
static const uint8_t kData2[] = {0x30, 3, 1, 2};
static const uint8_t kData3[] = {0x30, 0x80};
static const uint8_t kData4[] = {0x30, 0x81, 1, 1};
- static const uint8_t kData5[4 + 0x80] = {0x30, 0x82, 0, 0x80};
+ static const uint8_t kData5[] = {0x30, 0x82, 0, 1, 1};
static const uint8_t kData6[] = {0xa1, 3, 0x4, 1, 1};
static const uint8_t kData7[] = {0xa1, 3, 0x4, 2, 1};
static const uint8_t kData8[] = {0xa1, 3, 0x2, 1, 1};
@@ -649,14 +649,6 @@ static bool TestASN1Uint64() {
return true;
}
-static int TestZero() {
- CBB cbb;
- CBB_zero(&cbb);
- // Calling |CBB_cleanup| on a zero-state |CBB| must not crash.
- CBB_cleanup(&cbb);
- return 1;
-}
-
int main(void) {
CRYPTO_library_init();
@@ -673,8 +665,7 @@ int main(void) {
!TestCBBASN1() ||
!TestBerConvert() ||
!TestASN1Uint64() ||
- !TestGetOptionalASN1Bool() ||
- !TestZero()) {
+ !TestGetOptionalASN1Bool()) {
return 1;
}
diff --git a/src/crypto/bytestring/cbb.c b/src/crypto/bytestring/cbb.c
index 1da6a21..f1e09a2 100644
--- a/src/crypto/bytestring/cbb.c
+++ b/src/crypto/bytestring/cbb.c
@@ -20,10 +20,6 @@
#include <openssl/mem.h>
-void CBB_zero(CBB *cbb) {
- memset(cbb, 0, sizeof(CBB));
-}
-
static int cbb_init(CBB *cbb, uint8_t *buf, size_t cap) {
struct cbb_buffer_st *base;
@@ -247,11 +243,6 @@ int CBB_flush(CBB *cbb) {
return 1;
}
-size_t CBB_len(const CBB *cbb) {
- assert(cbb->child == NULL);
-
- return cbb->base->len;
-}
static int cbb_add_length_prefixed(CBB *cbb, CBB *out_contents,
size_t len_len) {
diff --git a/src/crypto/bytestring/cbs.c b/src/crypto/bytestring/cbs.c
index 5e0c538..b8caedd 100644
--- a/src/crypto/bytestring/cbs.c
+++ b/src/crypto/bytestring/cbs.c
@@ -137,15 +137,6 @@ int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) {
return 1;
}
-int CBS_copy_bytes(CBS *cbs, uint8_t *out, size_t len) {
- const uint8_t *v;
- if (!cbs_get(cbs, &v, len)) {
- return 0;
- }
- memcpy(out, v, len);
- return 1;
-}
-
static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) {
uint32_t len;
if (!cbs_get_u(cbs, &len, len_len)) {
@@ -329,19 +320,14 @@ int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
}
int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned tag) {
- int present = 0;
-
if (CBS_peek_asn1_tag(cbs, tag)) {
if (!CBS_get_asn1(cbs, out, tag)) {
return 0;
}
- present = 1;
- }
-
- if (out_present != NULL) {
- *out_present = present;
+ *out_present = 1;
+ } else {
+ *out_present = 0;
}
-
return 1;
}
diff --git a/src/crypto/bytestring/internal.h b/src/crypto/bytestring/internal.h
index b4ea7e5..391ad19 100644
--- a/src/crypto/bytestring/internal.h
+++ b/src/crypto/bytestring/internal.h
@@ -38,6 +38,14 @@ extern "C" {
* It returns one on success and zero otherwise. */
OPENSSL_EXPORT int CBS_asn1_ber_to_der(CBS *in, uint8_t **out, size_t *out_len);
+/* CBS_get_any_ber_asn1_element acts the same as |CBS_get_any_asn1_element| but
+ * also allows indefinite-length elements to be returned. In that case,
+ * |*out_header_len| and |CBS_len(out)| will both be two as only the header is
+ * returned. */
+OPENSSL_EXPORT int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out,
+ unsigned *out_tag,
+ size_t *out_header_len);
+
#if defined(__cplusplus)
} /* extern C */