xypriss-security
Version:
Advanced High-Performance Security Framework. Military-grade encryption, post-quantum resilience, and fortified data structures.
75 lines • 2.67 kB
JavaScript
;
/***************************************************************************
* XyPriss Security Core - SecureBuffer
*
* An enhanced Uint8Array that provides familiar encoding methods
* similar to Node.js Buffer, optimized for security operations.
*
* @author NEHONIX (Nehonix-Team - https://github.com/Nehonix-Team)
* @license Nehonix Open Source License (NOSL)
****************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecureBuffer = void 0;
const strulink_1 = require("strulink");
const encoding_1 = require("../utils/encoding");
/**
* ### SecureBuffer
*
* A specialized version of Uint8Array that includes high-performance
* encoding utilities. It maintains compatibility with standard Uint8Array
* while adding the flexibility of Node-style Buffers.
*/
class SecureBuffer extends Uint8Array {
/**
* Convert the buffer to a string with the specified encoding.
*
* @param encoding - The target encoding ('hex', 'base64', 'utf8', 'binary').
* @returns The encoded string.
*/
toString(encoding = "hex") {
switch (encoding.toLowerCase()) {
case "hex":
return (0, encoding_1.bufferToHex)(this);
case "base64":
return (0, encoding_1.bufferToBase64)(this);
case "utf8":
case "utf-8":
return (0, encoding_1.bufferToString)(this);
case "binary":
return (0, encoding_1.bufferToBinary)(this);
default:
// If it looks like a standard JS toString call (e.g. from String(buf))
// we might want to default to hex for security contexts or keep default.
// But the user specifically asked for encodings.
const rs = strulink_1.__strl__.encode(this.toString(), encoding);
console.log("using strulink");
return rs;
}
}
/**
* Alias for toBuffer() to maintain compatibility with older XyPriss versions.
*/
getBuffer() {
return this.toBuffer();
}
/**
* Returns a standard Node.js Buffer representation.
*/
toBuffer() {
return Buffer.from(this);
}
/**
* Returns a clean Uint8Array (stripping XyPriss enhancements).
*/
toUint8Array() {
return new Uint8Array(this);
}
/**
* Slice with SecureBuffer return type.
*/
slice(start, end) {
return new SecureBuffer(super.slice(start, end));
}
}
exports.SecureBuffer = SecureBuffer;
//# sourceMappingURL=SecureBuffer.js.map