Skip to content

Commit ae9054d

Browse files
committed
Remove highlighting and correct one module mismatch
1 parent f61bdf0 commit ae9054d

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

Diff for: src/core/operations/SM2Decrypt.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @license Apache-2.0
55
*/
66

7+
import OperationError from "../errors/OperationError.mjs";
78
import Operation from "../Operation.mjs";
89

910
import { SM2 } from "../lib/SM2.mjs";
@@ -54,6 +55,10 @@ class SM2Decrypt extends Operation {
5455
run(input, args) {
5556
const [privateKey, inputFormat, curveName] = args;
5657

58+
if (privateKey.length !== 64) {
59+
throw new OperationError("Input private key must be in hex; and should be 32 bytes");
60+
}
61+
5762
const sm2 = new SM2(curveName, inputFormat);
5863
sm2.setPrivateKey(privateKey);
5964

Diff for: src/core/operations/SM2Encrypt.mjs

+6-22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @license Apache-2.0
55
*/
66

7+
import OperationError from "../errors/OperationError.mjs";
78
import Operation from "../Operation.mjs";
89

910
import { SM2 } from "../lib/SM2.mjs";
@@ -20,7 +21,7 @@ class SM2Encrypt extends Operation {
2021
super();
2122

2223
this.name = "SM2 Encrypt";
23-
this.module = "Ciphers";
24+
this.module = "Crypto";
2425
this.description = "Encrypts a message utilizing the SM2 standard";
2526
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
2627
this.inputType = "ArrayBuffer";
@@ -61,33 +62,16 @@ class SM2Encrypt extends Operation {
6162
const [publicKeyX, publicKeyY, outputFormat, curveName] = args;
6263
this.outputFormat = outputFormat;
6364

65+
if (publicKeyX.length !== 64 || publicKeyY.length !== 64) {
66+
throw new OperationError("Invalid Public Key - Ensure each component is 32 bytes in size and in hex");
67+
}
68+
6469
const sm2 = new SM2(curveName, outputFormat);
6570
sm2.setPublicKey(publicKeyX, publicKeyY);
6671

6772
const result = sm2.encrypt(new Uint8Array(input));
6873
return result;
6974
}
70-
71-
/**
72-
* Highlight SM2 Encrypt
73-
*
74-
* @param {Object[]} pos
75-
* @param {number} pos[].start
76-
* @param {number} pos[].end
77-
* @param {Object[]} args
78-
* @returns {Object[]} pos
79-
*/
80-
highlight(pos, args) {
81-
const outputFormat = args[2];
82-
const num = pos[0].end - pos[0].start;
83-
let adjust = 128;
84-
if (outputFormat === "C1C3C2") {
85-
adjust = 192;
86-
}
87-
pos[0].start = Math.ceil(pos[0].start + adjust);
88-
pos[0].end = Math.floor(pos[0].end + adjust + num);
89-
return pos;
90-
}
9175
}
9276

9377
export default SM2Encrypt;

0 commit comments

Comments
 (0)