mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
Compare commits
1 commit
35137568bd
...
1bd21628e8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1bd21628e8 |
12 changed files with 40 additions and 224 deletions
|
@ -226,6 +226,7 @@ deno_core::extension!(deno_node,
|
||||||
ops::crypto::op_node_decipheriv_decrypt,
|
ops::crypto::op_node_decipheriv_decrypt,
|
||||||
ops::crypto::op_node_decipheriv_final,
|
ops::crypto::op_node_decipheriv_final,
|
||||||
ops::crypto::op_node_decipheriv_set_aad,
|
ops::crypto::op_node_decipheriv_set_aad,
|
||||||
|
ops::crypto::op_node_decipheriv_take,
|
||||||
ops::crypto::op_node_dh_compute_secret,
|
ops::crypto::op_node_dh_compute_secret,
|
||||||
ops::crypto::op_node_diffie_hellman,
|
ops::crypto::op_node_diffie_hellman,
|
||||||
ops::crypto::op_node_ecdh_compute_public_key,
|
ops::crypto::op_node_ecdh_compute_public_key,
|
||||||
|
|
|
@ -500,11 +500,6 @@ impl Decipher {
|
||||||
auth_tag: &[u8],
|
auth_tag: &[u8],
|
||||||
) -> Result<(), DecipherError> {
|
) -> Result<(), DecipherError> {
|
||||||
use Decipher::*;
|
use Decipher::*;
|
||||||
|
|
||||||
if input.is_empty() && !matches!(self, Aes128Gcm(_) | Aes256Gcm(_)) {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
match (self, auto_pad) {
|
match (self, auto_pad) {
|
||||||
(Aes128Cbc(decryptor), true) => {
|
(Aes128Cbc(decryptor), true) => {
|
||||||
assert!(input.len() == 16);
|
assert!(input.len() == 16);
|
||||||
|
|
|
@ -332,6 +332,17 @@ pub fn op_node_decipheriv_decrypt(
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[op2(fast)]
|
||||||
|
pub fn op_node_decipheriv_take(
|
||||||
|
state: &mut OpState,
|
||||||
|
#[smi] rid: u32,
|
||||||
|
) -> Result<(), cipher::DecipherContextError> {
|
||||||
|
let context = state.resource_table.take::<cipher::DecipherContext>(rid)?;
|
||||||
|
Rc::try_unwrap(context)
|
||||||
|
.map_err(|_| cipher::DecipherContextError::ContextInUse)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[op2]
|
#[op2]
|
||||||
pub fn op_node_decipheriv_final(
|
pub fn op_node_decipheriv_final(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
op_node_decipheriv_decrypt,
|
op_node_decipheriv_decrypt,
|
||||||
op_node_decipheriv_final,
|
op_node_decipheriv_final,
|
||||||
op_node_decipheriv_set_aad,
|
op_node_decipheriv_set_aad,
|
||||||
|
op_node_decipheriv_take,
|
||||||
op_node_private_decrypt,
|
op_node_private_decrypt,
|
||||||
op_node_private_encrypt,
|
op_node_private_encrypt,
|
||||||
op_node_public_encrypt,
|
op_node_public_encrypt,
|
||||||
|
@ -351,6 +352,14 @@ export class Decipheriv extends Transform implements Cipher {
|
||||||
}
|
}
|
||||||
|
|
||||||
final(encoding: string = getDefaultEncoding()): Buffer | string {
|
final(encoding: string = getDefaultEncoding()): Buffer | string {
|
||||||
|
if (!this.#needsBlockCache || this.#cache.cache.byteLength === 0) {
|
||||||
|
op_node_decipheriv_take(this.#context);
|
||||||
|
return encoding === "buffer" ? Buffer.from([]) : "";
|
||||||
|
}
|
||||||
|
if (this.#cache.cache.byteLength != 16) {
|
||||||
|
throw new Error("Invalid final block size");
|
||||||
|
}
|
||||||
|
|
||||||
let buf = new Buffer(16);
|
let buf = new Buffer(16);
|
||||||
op_node_decipheriv_final(
|
op_node_decipheriv_final(
|
||||||
this.#context,
|
this.#context,
|
||||||
|
@ -360,13 +369,6 @@ export class Decipheriv extends Transform implements Cipher {
|
||||||
this.#authTag || NO_TAG,
|
this.#authTag || NO_TAG,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!this.#needsBlockCache || this.#cache.cache.byteLength === 0) {
|
|
||||||
return encoding === "buffer" ? Buffer.from([]) : "";
|
|
||||||
}
|
|
||||||
if (this.#cache.cache.byteLength != 16) {
|
|
||||||
throw new Error("Invalid final block size");
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = buf.subarray(0, 16 - buf.at(-1)); // Padded in Pkcs7 mode
|
buf = buf.subarray(0, 16 - buf.at(-1)); // Padded in Pkcs7 mode
|
||||||
return encoding === "buffer" ? buf : buf.toString(encoding);
|
return encoding === "buffer" ? buf : buf.toString(encoding);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,12 +116,6 @@ deno_core::extension!(
|
||||||
"op_exit" | "op_set_exit_code" | "op_get_exit_code" =>
|
"op_exit" | "op_set_exit_code" | "op_get_exit_code" =>
|
||||||
op.with_implementation_from(&deno_core::op_void_sync()),
|
op.with_implementation_from(&deno_core::op_void_sync()),
|
||||||
_ => op,
|
_ => op,
|
||||||
},
|
|
||||||
state = |state| {
|
|
||||||
#[cfg(unix)]
|
|
||||||
{
|
|
||||||
state.put(ops::signal::SignalState::default());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ use opentelemetry::metrics::InstrumentBuilder;
|
||||||
use opentelemetry::metrics::MeterProvider as _;
|
use opentelemetry::metrics::MeterProvider as _;
|
||||||
use opentelemetry::otel_debug;
|
use opentelemetry::otel_debug;
|
||||||
use opentelemetry::otel_error;
|
use opentelemetry::otel_error;
|
||||||
use opentelemetry::trace::Link;
|
|
||||||
use opentelemetry::trace::SpanContext;
|
use opentelemetry::trace::SpanContext;
|
||||||
use opentelemetry::trace::SpanId;
|
use opentelemetry::trace::SpanId;
|
||||||
use opentelemetry::trace::SpanKind;
|
use opentelemetry::trace::SpanKind;
|
||||||
|
@ -95,7 +94,6 @@ deno_core::extension!(
|
||||||
op_otel_span_attribute1,
|
op_otel_span_attribute1,
|
||||||
op_otel_span_attribute2,
|
op_otel_span_attribute2,
|
||||||
op_otel_span_attribute3,
|
op_otel_span_attribute3,
|
||||||
op_otel_span_add_link,
|
|
||||||
op_otel_span_update_name,
|
op_otel_span_update_name,
|
||||||
op_otel_metric_attribute3,
|
op_otel_metric_attribute3,
|
||||||
op_otel_metric_record0,
|
op_otel_metric_record0,
|
||||||
|
@ -1326,6 +1324,17 @@ impl OtelSpan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fast]
|
||||||
|
fn drop_link(&self) {
|
||||||
|
let mut state = self.0.borrow_mut();
|
||||||
|
match &mut **state {
|
||||||
|
OtelSpanState::Recording(span) => {
|
||||||
|
span.links.dropped_count += 1;
|
||||||
|
}
|
||||||
|
OtelSpanState::Done(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[fast]
|
#[fast]
|
||||||
fn end(&self, end_time: f64) {
|
fn end(&self, end_time: f64) {
|
||||||
let end_time = if end_time.is_nan() {
|
let end_time = if end_time.is_nan() {
|
||||||
|
@ -1439,48 +1448,6 @@ fn op_otel_span_update_name<'s>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
|
||||||
fn op_otel_span_add_link<'s>(
|
|
||||||
scope: &mut v8::HandleScope<'s>,
|
|
||||||
span: v8::Local<'s, v8::Value>,
|
|
||||||
trace_id: v8::Local<'s, v8::Value>,
|
|
||||||
span_id: v8::Local<'s, v8::Value>,
|
|
||||||
#[smi] trace_flags: u8,
|
|
||||||
is_remote: bool,
|
|
||||||
#[smi] dropped_attributes_count: u32,
|
|
||||||
) -> bool {
|
|
||||||
let trace_id = parse_trace_id(scope, trace_id);
|
|
||||||
if trace_id == TraceId::INVALID {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
let span_id = parse_span_id(scope, span_id);
|
|
||||||
if span_id == SpanId::INVALID {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
let span_context = SpanContext::new(
|
|
||||||
trace_id,
|
|
||||||
span_id,
|
|
||||||
TraceFlags::new(trace_flags),
|
|
||||||
is_remote,
|
|
||||||
TraceState::NONE,
|
|
||||||
);
|
|
||||||
|
|
||||||
let Some(span) =
|
|
||||||
deno_core::_ops::try_unwrap_cppgc_object::<OtelSpan>(scope, span)
|
|
||||||
else {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
let mut state = span.0.borrow_mut();
|
|
||||||
if let OtelSpanState::Recording(span) = &mut **state {
|
|
||||||
span.links.links.push(Link::new(
|
|
||||||
span_context,
|
|
||||||
vec![],
|
|
||||||
dropped_attributes_count,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
struct OtelMeter(opentelemetry::metrics::Meter);
|
struct OtelMeter(opentelemetry::metrics::Meter);
|
||||||
|
|
||||||
impl deno_core::GarbageCollected for OtelMeter {}
|
impl deno_core::GarbageCollected for OtelMeter {}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import {
|
||||||
op_otel_metric_record2,
|
op_otel_metric_record2,
|
||||||
op_otel_metric_record3,
|
op_otel_metric_record3,
|
||||||
op_otel_metric_wait_to_observe,
|
op_otel_metric_wait_to_observe,
|
||||||
op_otel_span_add_link,
|
|
||||||
op_otel_span_attribute1,
|
op_otel_span_attribute1,
|
||||||
op_otel_span_attribute2,
|
op_otel_span_attribute2,
|
||||||
op_otel_span_attribute3,
|
op_otel_span_attribute3,
|
||||||
|
@ -187,6 +186,7 @@ interface OtelSpan {
|
||||||
spanContext(): SpanContext;
|
spanContext(): SpanContext;
|
||||||
setStatus(status: SpanStatusCode, errorDescription: string): void;
|
setStatus(status: SpanStatusCode, errorDescription: string): void;
|
||||||
dropEvent(): void;
|
dropEvent(): void;
|
||||||
|
dropLink(): void;
|
||||||
end(endTime: number): void;
|
end(endTime: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,24 +359,14 @@ class Span {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLink(link: Link): Span {
|
addLink(_link: Link): Span {
|
||||||
const droppedAttributeCount = (link.droppedAttributesCount ?? 0) +
|
this.#otelSpan?.dropLink();
|
||||||
(link.attributes ? ObjectKeys(link.attributes).length : 0);
|
|
||||||
const valid = op_otel_span_add_link(
|
|
||||||
this.#otelSpan,
|
|
||||||
link.context.traceId,
|
|
||||||
link.context.spanId,
|
|
||||||
link.context.traceFlags,
|
|
||||||
link.context.isRemote ?? false,
|
|
||||||
droppedAttributeCount,
|
|
||||||
);
|
|
||||||
if (!valid) return this;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLinks(links: Link[]): Span {
|
addLinks(links: Link[]): Span {
|
||||||
for (let i = 0; i < links.length; i++) {
|
for (let i = 0; i < links.length; i++) {
|
||||||
this.addLink(links[i]);
|
this.#otelSpan?.dropLink();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
"dist": {
|
"dist": {
|
||||||
"integrity": "sha512-m27K11aQalRbmUs7RLaz6aPyceLjAoqjPRNTdE7qUouQpl+PC8Bi67O+i9SuJUPbQC8dxFrczAxfmTPuTKHNkw==",
|
"integrity": "sha512-m27K11aQalRbmUs7RLaz6aPyceLjAoqjPRNTdE7qUouQpl+PC8Bi67O+i9SuJUPbQC8dxFrczAxfmTPuTKHNkw==",
|
||||||
"shasum": "15b07567befb2b914aedbb55a9ea0862c63c3d73",
|
"shasum": "15b07567befb2b914aedbb55a9ea0862c63c3d73",
|
||||||
"tarball": "http://localhost:4260/dns2/dns2-2.1.0.tgz",
|
"tarball": "https://registry.npmjs.org/dns2/-/dns2-2.1.0.tgz",
|
||||||
"fileCount": 37,
|
"fileCount": 37,
|
||||||
"unpackedSize": 75538
|
"unpackedSize": 75538
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,10 +22,6 @@
|
||||||
},
|
},
|
||||||
"args": "run -A main.ts metric.ts",
|
"args": "run -A main.ts metric.ts",
|
||||||
"output": "metric.out"
|
"output": "metric.out"
|
||||||
},
|
|
||||||
"links": {
|
|
||||||
"args": "run -A main.ts links.ts",
|
|
||||||
"output": "links.out"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
{
|
|
||||||
"spans": [
|
|
||||||
{
|
|
||||||
"traceId": "00000000000000000000000000000001",
|
|
||||||
"spanId": "0000000000000001",
|
|
||||||
"traceState": "",
|
|
||||||
"parentSpanId": "",
|
|
||||||
"flags": 1,
|
|
||||||
"name": "example span",
|
|
||||||
"kind": 1,
|
|
||||||
"startTimeUnixNano": "[WILDCARD]",
|
|
||||||
"endTimeUnixNano": "[WILDCARD]",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 0,
|
|
||||||
"events": [],
|
|
||||||
"droppedEventsCount": 0,
|
|
||||||
"links": [
|
|
||||||
{
|
|
||||||
"traceId": "1234567890abcdef1234567890abcdef",
|
|
||||||
"spanId": "1234567890abcdef",
|
|
||||||
"traceState": "",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 0,
|
|
||||||
"flags": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"droppedLinksCount": 0,
|
|
||||||
"status": {
|
|
||||||
"message": "",
|
|
||||||
"code": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"traceId": "00000000000000000000000000000002",
|
|
||||||
"spanId": "0000000000000002",
|
|
||||||
"traceState": "",
|
|
||||||
"parentSpanId": "",
|
|
||||||
"flags": 1,
|
|
||||||
"name": "example span",
|
|
||||||
"kind": 1,
|
|
||||||
"startTimeUnixNano": "[WILDCARD]",
|
|
||||||
"endTimeUnixNano": "[WILDCARD]",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 0,
|
|
||||||
"events": [],
|
|
||||||
"droppedEventsCount": 0,
|
|
||||||
"links": [
|
|
||||||
{
|
|
||||||
"traceId": "1234567890abcdef1234567890abcdef",
|
|
||||||
"spanId": "1234567890abcdef",
|
|
||||||
"traceState": "",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 0,
|
|
||||||
"flags": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"droppedLinksCount": 0,
|
|
||||||
"status": {
|
|
||||||
"message": "",
|
|
||||||
"code": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"traceId": "00000000000000000000000000000003",
|
|
||||||
"spanId": "0000000000000003",
|
|
||||||
"traceState": "",
|
|
||||||
"parentSpanId": "",
|
|
||||||
"flags": 1,
|
|
||||||
"name": "example span",
|
|
||||||
"kind": 1,
|
|
||||||
"startTimeUnixNano": "[WILDCARD]",
|
|
||||||
"endTimeUnixNano": "[WILDCARD]",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 0,
|
|
||||||
"events": [],
|
|
||||||
"droppedEventsCount": 0,
|
|
||||||
"links": [
|
|
||||||
{
|
|
||||||
"traceId": "1234567890abcdef1234567890abcdef",
|
|
||||||
"spanId": "1234567890abcdef",
|
|
||||||
"traceState": "",
|
|
||||||
"attributes": [],
|
|
||||||
"droppedAttributesCount": 2,
|
|
||||||
"flags": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"droppedLinksCount": 0,
|
|
||||||
"status": {
|
|
||||||
"message": "",
|
|
||||||
"code": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"logs": [],
|
|
||||||
"metrics": []
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
||||||
|
|
||||||
import { trace } from "npm:@opentelemetry/api@1.9.0";
|
|
||||||
|
|
||||||
const tracer = trace.getTracer("example-tracer");
|
|
||||||
|
|
||||||
const span1 = tracer.startSpan("example span", {
|
|
||||||
links: [{
|
|
||||||
context: {
|
|
||||||
traceId: "1234567890abcdef1234567890abcdef",
|
|
||||||
spanId: "1234567890abcdef",
|
|
||||||
traceFlags: 1,
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
span1.end();
|
|
||||||
|
|
||||||
const span2 = tracer.startSpan("example span");
|
|
||||||
span2.addLink({
|
|
||||||
context: {
|
|
||||||
traceId: "1234567890abcdef1234567890abcdef",
|
|
||||||
spanId: "1234567890abcdef",
|
|
||||||
traceFlags: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
span2.end();
|
|
||||||
|
|
||||||
const span3 = tracer.startSpan("example span");
|
|
||||||
span3.addLink({
|
|
||||||
context: {
|
|
||||||
traceId: "1234567890abcdef1234567890abcdef",
|
|
||||||
spanId: "1234567890abcdef",
|
|
||||||
traceFlags: 1,
|
|
||||||
},
|
|
||||||
attributes: {
|
|
||||||
key: "value",
|
|
||||||
},
|
|
||||||
droppedAttributesCount: 1,
|
|
||||||
});
|
|
||||||
span3.end();
|
|
|
@ -4,7 +4,7 @@ import crypto from "node:crypto";
|
||||||
import { Buffer } from "node:buffer";
|
import { Buffer } from "node:buffer";
|
||||||
import testVectors128 from "./gcmEncryptExtIV128.json" with { type: "json" };
|
import testVectors128 from "./gcmEncryptExtIV128.json" with { type: "json" };
|
||||||
import testVectors256 from "./gcmEncryptExtIV256.json" with { type: "json" };
|
import testVectors256 from "./gcmEncryptExtIV256.json" with { type: "json" };
|
||||||
import { assertEquals, assertThrows } from "@std/assert";
|
import { assertEquals } from "@std/assert";
|
||||||
|
|
||||||
const aesGcm = (bits: string, key: Uint8Array) => {
|
const aesGcm = (bits: string, key: Uint8Array) => {
|
||||||
const ALGO = bits == "128" ? `aes-128-gcm` : `aes-256-gcm`;
|
const ALGO = bits == "128" ? `aes-128-gcm` : `aes-256-gcm`;
|
||||||
|
@ -123,7 +123,7 @@ Deno.test({
|
||||||
// Issue #27441
|
// Issue #27441
|
||||||
// https://github.com/denoland/deno/issues/27441
|
// https://github.com/denoland/deno/issues/27441
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "aes-256-gcm supports IV of non standard length and auth tag check",
|
name: "aes-256-gcm supports IV of non standard length",
|
||||||
fn() {
|
fn() {
|
||||||
const decipher = crypto.createDecipheriv(
|
const decipher = crypto.createDecipheriv(
|
||||||
"aes-256-gcm",
|
"aes-256-gcm",
|
||||||
|
@ -136,10 +136,6 @@ Deno.test({
|
||||||
"utf-8",
|
"utf-8",
|
||||||
);
|
);
|
||||||
assertEquals(decrypted, "this is a secret");
|
assertEquals(decrypted, "this is a secret");
|
||||||
assertThrows(
|
decipher.final();
|
||||||
() => decipher.final(),
|
|
||||||
TypeError,
|
|
||||||
"Failed to authenticate data",
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue