CidUtils.java

1
package org.cardanofoundation.explorer.api.util;
2
3
import lombok.extern.log4j.Log4j2;
4
5
import com.bloxbean.cardano.client.crypto.Blake2bUtil;
6
import io.ipfs.cid.Cid;
7
import io.ipfs.multibase.Multibase;
8
import io.ipfs.multihash.Multihash;
9
import org.erdtman.jcs.JsonCanonicalizer;
10
11
@Log4j2
12
public class CidUtils {
13
14
  public static boolean verifyCid(String cid, String jsonData) {
15
    try {
16
      String json = new JsonCanonicalizer(jsonData).getEncodedString();
17 2 1. verifyCid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED
2. verifyCid : replaced boolean return with false for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED
      return cid.equals(generateCid(json));
18
    } catch (Exception e) {
19
      log.error("Error while verifying cid", e);
20 1 1. verifyCid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED
      return false;
21
    }
22
  }
23
24
  private static String generateCid(String canonicalized) {
25
    // Get bytes to hash.
26
    byte[] canonicalizedBytes = canonicalized.getBytes();
27
28
    // Blake2b-256 as the hashing algorithm.
29
    byte[] hashed = Blake2bUtil.blake2bHash256(canonicalizedBytes);
30
31
    // Content Identifier (CID) as defined by Multiformats (Protocol Labs).
32
    Cid cid = new Cid(1, Cid.Codec.Raw, Multihash.Type.blake2b_256, hashed);
33
34
    // CID be represented in Multibase format with base58btc encoding.
35 1 1. generateCid : replaced return value with "" for org/cardanofoundation/explorer/api/util/CidUtils::generateCid → KILLED
    return Multibase.encode(Multibase.Base.Base58BTC, cid.toBytes());
36
  }
37
}

Mutations

17

1.1
Location : verifyCid
Killed by : org.cardanofoundation.explorer.api.util.CidUtilsTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.util.CidUtilsTest]/[method:verifyCid_shouldReturnFalse_whenCidIsInvalid()]
replaced boolean return with true for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED

2.2
Location : verifyCid
Killed by : org.cardanofoundation.explorer.api.util.CidUtilsTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.util.CidUtilsTest]/[method:verifyCid_shouldReturnTrue_whenCidIsValid()]
replaced boolean return with false for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED

20

1.1
Location : verifyCid
Killed by : org.cardanofoundation.explorer.api.util.CidUtilsTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.util.CidUtilsTest]/[method:verifyCid_shouldReturnFalse_whenExceptionIsThrown()]
replaced boolean return with true for org/cardanofoundation/explorer/api/util/CidUtils::verifyCid → KILLED

35

1.1
Location : generateCid
Killed by : org.cardanofoundation.explorer.api.util.CidUtilsTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.util.CidUtilsTest]/[method:verifyCid_shouldReturnTrue_whenCidIsValid()]
replaced return value with "" for org/cardanofoundation/explorer/api/util/CidUtils::generateCid → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2