Skip to content

Commit

Permalink
Fix Sonar Code Smells (#25)
Browse files Browse the repository at this point in the history
* decode ec certificates

* fix ec signature computation

* junit for signing

* sonar

* Fix coverage exclusions

* Remove Sonar Coverage exclusion properties

* Refactoring

* fix Sonar Code Smells

* Checkstyle

Co-authored-by: Artur T <[email protected]>
  • Loading branch information
f11h and a-trzewik committed May 3, 2021
1 parent 5186b74 commit 7bd9c76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public ResponseEntity<EgcDecodeResult> decodeEgCert(

try {
oneKey = new OneKey(map);
message = (Sign1Message) Sign1Message.DecodeFromBytes(cose);
message = (Sign1Message) COSE.Message.DecodeFromBytes(cose);
} catch (CoseException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ private CBORObject getEcCurve(ECPublicKey publicKey) {
}

private CBORObject stripLeadingZero(BigInteger input) {
val bytes = input.toByteArray();
final byte[] bytes = input.toByteArray();
byte[] stripped;

if (bytes.length % 8 != 0 && bytes[0] == 0x00) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.europa.ec.dgc.issuance.service.impl;

import eu.europa.ec.dgc.issuance.service.SigningService;
import java.io.IOException;
import java.math.BigInteger;
import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateCrtKey;
Expand Down Expand Up @@ -29,7 +28,7 @@ public byte[] signHash(byte[] hashBytes, PrivateKey privateKey) {
} else {
signature = signEc(hashBytes, privateKey);
}
} catch (CryptoException | IOException e) {
} catch (CryptoException e) {
throw new IllegalArgumentException("error during signing ", e);
}
return signature;
Expand All @@ -50,7 +49,7 @@ private byte[] signRsapss(byte[] hashBytes, PrivateKey privateKey) throws Crypto
return pssSigner.generateSignature();
}

private byte[] signEc(byte[] hash, PrivateKey privateKey) throws IOException {
private byte[] signEc(byte[] hash, PrivateKey privateKey) {
java.security.interfaces.ECPrivateKey privKey = (java.security.interfaces.ECPrivateKey) privateKey;
ECParameterSpec s = EC5Util.convertSpec(privKey.getParams());
ECPrivateKeyParameters keyparam = new ECPrivateKeyParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
@Service
public class CborDumpService {

/**
* Method to write a CBOR Array into a {@link Writer} (e.g. {@link java.io.StringWriter}).
*
* @param cb cbor Byte Array to write
* @param writer destination
*/
public void dumpCbor(byte[] cb, Writer writer) throws IOException {
CBORObject cborObject = CBORObject.DecodeFromBytes(cb);
dumpCbor(cborObject, writer, 0);
}

private void dumpCbor(CBORObject cborObject, Writer writer, int ident) throws IOException {
writer
.append("")
.append(String.valueOf(cborObject));
Expand Down

0 comments on commit 7bd9c76

Please sign in to comment.