diff options
author | James M Snell <jasnell@gmail.com> | 2020-08-25 20:05:51 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2020-10-08 03:27:05 +0300 |
commit | dae283d96fd31ad0f30840a7e55ac97294f505ac (patch) | |
tree | 8f7f87e50411e8965cb83d9b280035f36d355fbc /src/string_bytes.cc | |
parent | ba77dc8597cbcf42feea59f1381512d421ec9cc5 (diff) |
crypto: refactoring internals, add WebCrypto
Fixes: https://github.com/nodejs/node/issues/678
Refs: https://github.com/nodejs/node/issues/26854
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/35093
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index b03268c49af..556dba97c09 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -358,6 +358,8 @@ size_t StringBytes::Write(Isolate* isolate, break; } + case BASE64URL: + // Fall through case BASE64: if (str->IsExternalOneByte()) { auto ext = str->GetExternalOneByteStringResource(); @@ -425,6 +427,8 @@ Maybe<size_t> StringBytes::StorageSize(Isolate* isolate, data_size = str->Length() * sizeof(uint16_t); break; + case BASE64URL: + // Fall through case BASE64: data_size = base64_decoded_size_fast(str->Length()); break; @@ -466,6 +470,8 @@ Maybe<size_t> StringBytes::Size(Isolate* isolate, case UCS2: return Just(str->Length() * sizeof(uint16_t)); + case BASE64URL: + // Fall through case BASE64: { String::Value value(isolate, str); return Just(base64_decoded_size(*value, value.length())); @@ -691,6 +697,20 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate, return ExternOneByteString::New(isolate, dst, dlen, error); } + case BASE64URL: { + size_t dlen = base64_encoded_size(buflen, Base64Mode::URL); + char* dst = node::UncheckedMalloc(dlen); + if (dst == nullptr) { + *error = node::ERR_MEMORY_ALLOCATION_FAILED(isolate); + return MaybeLocal<Value>(); + } + + size_t written = base64_encode(buf, buflen, dst, dlen, Base64Mode::URL); + CHECK_EQ(written, dlen); + + return ExternOneByteString::New(isolate, dst, dlen, error); + } + case HEX: { size_t dlen = buflen * 2; char* dst = node::UncheckedMalloc(dlen); |