Skip to content

Commit 3c4037a

Browse files
authored
Create crypto-utils.js
Signed-off-by: Mustapha BARKI <code4yo@gmail.com>
1 parent 7b974cb commit 3c4037a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const MAX_BUFFER_SIZE = 1024; // 1KB
2+
3+
function safeBufferConversion(input, encoding = 'hex') {
4+
if (input.length > MAX_BUFFER_SIZE * 2 && encoding === 'hex') {
5+
throw new SecurityError('Input exceeds maximum allowed size');
6+
}
7+
return Buffer.from(input, encoding);
8+
}
9+
10+
class SecurityError extends Error {
11+
constructor(message) {
12+
super(message);
13+
this.name = 'SecurityError';
14+
// Remove stack trace for production
15+
if (process.env.NODE_ENV === 'production') {
16+
this.stack = undefined;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)