diff options
author | Doug Hogan <doug@cvs.openbsd.org> | 2015-06-23 05:58:29 +0000 |
---|---|---|
committer | Doug Hogan <doug@cvs.openbsd.org> | 2015-06-23 05:58:29 +0000 |
commit | b53a5bc992e71b557d23822b11b89694af485457 (patch) | |
tree | afabe5e09b9fef1e476f4befb8c6e44d2fc41076 /regress/lib/libssl | |
parent | dbb4212fd39132cf1d5b343c43a45ce687e9a6cd (diff) |
Change CBS_dup() to also sync the offset.
Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.
ok miod@ jsing@
Diffstat (limited to 'regress/lib/libssl')
-rw-r--r-- | regress/lib/libssl/bytestring/bytestringtest.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/regress/lib/libssl/bytestring/bytestringtest.c b/regress/lib/libssl/bytestring/bytestringtest.c index d989868c852..3275e6f2c72 100644 --- a/regress/lib/libssl/bytestring/bytestringtest.c +++ b/regress/lib/libssl/bytestring/bytestringtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestringtest.c,v 1.7 2015/06/23 01:20:24 doug Exp $ */ +/* $OpenBSD: bytestringtest.c,v 1.8 2015/06/23 05:58:28 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -751,6 +751,41 @@ err: return ret; } +static int +test_cbs_dup(void) +{ + CBS data, check; + static const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'}; + + CBS_init(&data, input, sizeof(input)); + CHECK(CBS_len(&data) == 6); + CBS_dup(&data, &check); + CHECK(CBS_len(&check) == 6); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_skip(&data, 1)); + CHECK(CBS_len(&data) == 5); + CHECK(CBS_len(&check) == 6); + CHECK(CBS_data(&data) == CBS_data(&check) + 1); + CHECK(CBS_skip(&check, 1)); + CHECK(CBS_len(&data) == 5); + CHECK(CBS_len(&check) == 5); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_offset(&data) == 1); + CHECK(CBS_offset(&check) == 1); + + CBS_init(&data, input, sizeof(input)); + CHECK(CBS_skip(&data, 5)); + CBS_dup(&data, &check); + CHECK(CBS_len(&data) == 1); + CHECK(CBS_len(&check) == 1); + CHECK(CBS_data(&data) == input + 5); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_offset(&data) == 5); + CHECK(CBS_offset(&check) == 5); + + return 1; +} + int main(void) { @@ -772,6 +807,7 @@ main(void) failed |= !test_get_optional_asn1_bool(); failed |= !test_offset(); failed |= !test_write_bytes(); + failed |= !test_cbs_dup(); if (!failed) printf("PASS\n"); |