How to use the @aws-sdk/util-hex-encoding.toHex function in @aws-sdk/util-hex-encoding

To help you get started, we’ve selected a few @aws-sdk/util-hex-encoding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-sdk-js-v3 / packages / signature-v4 / src / getPayloadHash.ts View on Github external
for (const headerName of Object.keys(headers)) {
    if (headerName.toLowerCase() === SHA256_HEADER) {
      return headers[headerName];
    }
  }

  if (body == undefined) {
    return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
  } else if (
    typeof body === "string" ||
    ArrayBuffer.isView(body) ||
    isArrayBuffer(body)
  ) {
    const hashCtor = new hashConstructor();
    hashCtor.update(body);
    return toHex(await hashCtor.digest());
  }

  // As any defined body that is not a string or binary data is a stream, this
  // body is unsignable. Attempt to send the request with an unsigned payload,
  // which may or may not be accepted by the service.
  return UNSIGNED_PAYLOAD;
}
github aws / aws-sdk-js-v3 / packages / md5-js / src / index.spec.ts View on Github external
it(`should calculate a MD5 hash of ${expected} for test vector ${++idx}`, async () => {
      const hash = new Md5();
      hash.update(fromBase64(input));
      expect(toHex(await hash.digest())).toBe(expected);
    });
  }
github aws / aws-sdk-js-v3 / packages / hash-stream-node / src / index.spec.ts View on Github external
it("calculates the SHA256 hash of a stream", async () => {
    const result = await calculateSha256(
      Sha256,
      createReadStream(temporaryFile)
    );

    expect(result instanceof Uint8Array).toBe(true);
    expect(toHex(result)).toBe(
      "24dabf4db3774a3224d571d4c089a9c570c3045dbe1e67ee9ee2e2677f57dbe0"
    );
  });
github aws / aws-sdk-js-v3 / packages / sha256-tree-hash / src / index.spec.ts View on Github external
it("computes tree hashes of string bodies", async () => {
    const treeHash = new TreeHash(Sha256, fromUtf8);
    treeHash.update("bar");
    const results = await treeHash.digest();
    expect(toHex(results)).toEqual(
      "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
    );
  });
github aws / aws-sdk-js-v3 / packages / hash-blob-browser / src / index.spec.ts View on Github external
it("calculates the SHA256 hash of a blob", async () => {
    const result = await calculateSha256(Sha256, blob);

    expect(result instanceof Uint8Array).toBe(true);
    expect(toHex(result)).toBe(
      "24dabf4db3774a3224d571d4c089a9c570c3045dbe1e67ee9ee2e2677f57dbe0"
    );
  });
});
github aws / aws-sdk-js-v3 / packages / eventstream-marshaller / src / Int64.ts View on Github external
valueOf(): number {
    const bytes = this.bytes.slice(0);
    const negative = bytes[0] & 0b10000000;
    if (negative) {
      negate(bytes);
    }

    return parseInt(toHex(bytes), 16) * (negative ? -1 : 1);
  }
github aws / aws-sdk-js-v3 / packages / eventstream-marshaller / src / HeaderMarshaller.ts View on Github external
)
          };
          position += 8;
          break;
        case HEADER_VALUE_TYPE.uuid:
          const uuidBytes = new Uint8Array(
            headers.buffer,
            headers.byteOffset + position,
            16
          );
          position += 16;
          out[name] = {
            type: UUID_TAG,
            value: `${toHex(uuidBytes.subarray(0, 4))}-${toHex(
              uuidBytes.subarray(4, 6)
            )}-${toHex(uuidBytes.subarray(6, 8))}-${toHex(
              uuidBytes.subarray(8, 10)
            )}-${toHex(uuidBytes.subarray(10))}`
          };
          break;
        default:
          throw new Error(`Unrecognized header type tag`);
      }
    }

    return out;
  }
}

@aws-sdk/util-hex-encoding

Converts binary buffers to and from lowercase hexadecimal encoding

Apache-2.0
Latest version published 1 year ago

Package Health Score

72 / 100
Full package analysis

Popular @aws-sdk/util-hex-encoding functions

Similar packages