summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2024-11-25 12:13:15 +0100
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2024-11-25 12:13:15 +0100
commit4e346153923fe254229fe1eeeccde2cb442c01c1 (patch)
tree29fdd5c63b616fa91268e7c7ac84a7f2db4657ed
parentMerge pull request #90 from craftbyte/master (diff)
downloadUIC-barcode-consolidate_signed_data_in_static_frame.tar
UIC-barcode-consolidate_signed_data_in_static_frame.tar.gz
UIC-barcode-consolidate_signed_data_in_static_frame.tar.bz2
UIC-barcode-consolidate_signed_data_in_static_frame.tar.lz
UIC-barcode-consolidate_signed_data_in_static_frame.tar.xz
UIC-barcode-consolidate_signed_data_in_static_frame.tar.zst
UIC-barcode-consolidate_signed_data_in_static_frame.zip
-rw-r--r--src/main/java/org/uic/barcode/Decoder.java4
-rw-r--r--src/main/java/org/uic/barcode/Encoder.java2
-rw-r--r--src/main/java/org/uic/barcode/staticFrame/StaticFrame.java54
3 files changed, 26 insertions, 34 deletions
diff --git a/src/main/java/org/uic/barcode/Decoder.java b/src/main/java/org/uic/barcode/Decoder.java
index 1e0a02d..81e0ba2 100644
--- a/src/main/java/org/uic/barcode/Decoder.java
+++ b/src/main/java/org/uic/barcode/Decoder.java
@@ -374,7 +374,7 @@ public class Decoder {
if (!isStaticHeader(data) && dynamicFrame != null) {
return dynamicFrame.getLevel1DataBin();
} else if (staticFrame != null) {
- return staticFrame.getDataForSignature();
+ return staticFrame.buildDataForSignature();
} else {
throw new EncodingFormatException("Unknown Header");
}
@@ -385,7 +385,7 @@ public class Decoder {
if (!isStaticHeader(data)) {
return dynamicFrame.getLevel2Data().getLevel1Signature();
} else if (staticFrame != null) {
- return staticFrame.getDataForSignature();
+ return staticFrame.buildDataForSignature();
} else {
throw new EncodingFormatException("Unknown Header");
}
diff --git a/src/main/java/org/uic/barcode/Encoder.java b/src/main/java/org/uic/barcode/Encoder.java
index e9874cf..904adce 100644
--- a/src/main/java/org/uic/barcode/Encoder.java
+++ b/src/main/java/org/uic/barcode/Encoder.java
@@ -490,7 +490,7 @@ public class Encoder {
if (dynamicFrame != null) {
return DynamicFrameCoder.encodeLevel1(dynamicFrame);
} else if (staticFrame != null) {
- return staticFrame.getDataForSignature();
+ return staticFrame.buildDataForSignature();
} else {
throw new EncodingFormatException("Unknown Header");
}
diff --git a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
index c0f03c8..3475bc4 100644
--- a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
+++ b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
@@ -294,10 +294,14 @@ public class StaticFrame {
* @throws IOException Signals that an I/O exception has occurred.
* @throws EncodingFormatException the encoding format exception
*/
- public byte[] getDataForSignature() throws IOException, EncodingFormatException {
- // data compression
- if (signedData != null) return signedData;
+ public byte[] buildDataForSignature() throws IOException, EncodingFormatException {
+ if (signedData != null) {
+ //signed data already build
+ return signedData;
+ }
+
+ // data compression
Deflater deflater = new Deflater();
byte[] data = encodeData();
deflater.setInput(data);
@@ -310,7 +314,18 @@ public class StaticFrame {
}
compressStream.close();
- return compressStream.toByteArray();
+ signedData = compressStream.toByteArray();
+
+ return signedData;
+ }
+
+ /**
+ * Gets the data for signing.
+ *
+ * @return the data to be signed
+ */
+ public byte[] getDataForSignature() {
+ return signedData;
}
/**
@@ -620,30 +635,6 @@ public class StaticFrame {
}
-
- /**
- * Verify the signature
- *
- * Note: an appropriate security provider (e.g. BC) must be registered before
- *
- * @param key the key
- * @param algo the algorithm name
- * @return true, if successful
- * @throws InvalidKeyException the invalid key exception
- * @throws NoSuchAlgorithmException the no such algorithm exception
- * @throws SignatureException the signature exception
- * @throws IllegalArgumentException the illegal argument exception
- * @throws UnsupportedOperationException the unsupported operation exception
- * @throws EncodingFormatException
- * @throws IOException
- */
- public boolean ByAlgorithmName(PublicKey key, String algo) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, IllegalArgumentException, UnsupportedOperationException, IOException, EncodingFormatException {
- Signature sig = Signature.getInstance(algo);
- sig.initVerify(key);
- sig.update(this.getDataForSignature());
- return sig.verify(this.getSignature());
- }
-
/**
* Verify the signature
*
@@ -659,6 +650,7 @@ public class StaticFrame {
* @throws UnsupportedOperationException the unsupported operating exception
* @throws EncodingFormatException
* @throws IOException
+ * @deprecated
*/
public boolean verifyByAlgorithmOid(PublicKey key, String signingAlg) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, IllegalArgumentException, UnsupportedOperationException, IOException, EncodingFormatException {
@@ -778,7 +770,7 @@ public class StaticFrame {
}
Signature sig = Signature.getInstance(algo);
sig.initSign(key);
- signedData = getDataForSignature();
+ signedData = buildDataForSignature();
sig.update(signedData);
signature = sig.sign();
}
@@ -833,7 +825,7 @@ public class StaticFrame {
}
sig.initSign(key);
- signedData = getDataForSignature();
+ signedData = buildDataForSignature();
sig.update(signedData);
signature = sig.sign();
}
@@ -857,7 +849,7 @@ public class StaticFrame {
public void signUsingAlgorithmName(PrivateKey key,String algo) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, IOException, EncodingFormatException {
Signature sig = Signature.getInstance(algo);
sig.initSign(key);
- sig.update(getDataForSignature());
+ sig.update(buildDataForSignature());
signature = sig.sign();
}