Commit 6641225f authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Use BoringSSL's implementation of IsValidInteger.

Saves a tiny bit of code.

Change-Id: I694306ac83c425a2d42c7381f9bc024c417591b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547760Reviewed-by: default avatarRyan Sleevi <rsleevi@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828934}
parent 7056ad03
......@@ -8,6 +8,7 @@
#include "base/check_op.h"
#include "base/notreached.h"
#include "third_party/boringssl/src/include/openssl/bytestring.h"
namespace net {
......@@ -153,22 +154,14 @@ bool ParseBoolRelaxed(const Input& in, bool* out) {
// one octet, then the bits of the first octet and the most significant bit
// of the second octet must not be all zeroes or all ones.
bool IsValidInteger(const Input& in, bool* negative) {
der::ByteReader reader(in);
uint8_t first_byte;
if (!reader.ReadByte(&first_byte))
return false; // Empty inputs are not allowed.
uint8_t second_byte;
if (reader.ReadByte(&second_byte)) {
if ((first_byte == 0x00 || first_byte == 0xFF) &&
(first_byte & 0x80) == (second_byte & 0x80)) {
// Not a minimal encoding.
return false;
}
CBS cbs;
CBS_init(&cbs, in.UnsafeData(), in.Length());
int negative_int;
if (!CBS_is_valid_asn1_integer(&cbs, &negative_int)) {
return false;
}
*negative = (first_byte & 0x80) == 0x80;
*negative = !!negative_int;
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment