Java Code Examples for org.bouncycastle.util.Arrays#areEqual()

The following examples show how to use org.bouncycastle.util.Arrays#areEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Script.java    From bushido-java-core with GNU General Public License v3.0 6 votes vote down vote up
public boolean equals(Script script) {
    if (chunks.size() != script.chunks.size()) {
        return false;
    }
    for (int i = 0; i < chunks.size(); i++) {
        if (chunks.get(i).bytes != null && script.chunks.get(i).bytes == null) {
            return false;
        }
        if (chunks.get(i).opcode.value != script.chunks.get(i).opcode.value) {
            return false;
        }
        if (Arrays.areEqual(chunks.get(i).bytes, script.chunks.get(i).bytes) == false) {
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: CassandraRow.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getPartitionKey() {
  byte[] partitionKey = row.getBytes(CassandraField.GW_PARTITION_ID_KEY.getFieldName()).array();
  if (Arrays.areEqual(CassandraUtils.EMPTY_PARTITION_KEY, partitionKey)) {
    // we shouldn't expose the reserved "empty" partition key externally
    return new byte[0];
  }
  return partitionKey;
}
 
Example 3
Source File: Hash.java    From bop-bitcoin-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals (Object obj)
{
	if ( this == obj )
	{
		return true;
	}
	if ( obj != null && obj instanceof Hash )
	{
		return Arrays.areEqual (bytes, ((Hash) obj).bytes);
	}
	return false;
}
 
Example 4
Source File: ExtendedKey.java    From bop-bitcoin-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals (Object obj)
{
	if ( obj instanceof ExtendedKey )
	{
		return master.equals (((ExtendedKey) obj).master) && Arrays.areEqual (chainCode, ((ExtendedKey) obj).chainCode)
				&& depth == ((ExtendedKey) obj).depth &&
				parent == ((ExtendedKey) obj).parent && sequence == ((ExtendedKey) obj).sequence;
	}
	return false;
}
 
Example 5
Source File: DynamoDBRow.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static GeoWaveKey getGeoWaveKey(final Map<String, AttributeValue> objMap) {
  final byte[] partitionKey = objMap.get(GW_PARTITION_ID_KEY).getB().array();

  final byte[] rangeKey = objMap.get(GW_RANGE_KEY).getB().array();
  final int length = rangeKey.length;

  final ByteBuffer metadataBuf = ByteBuffer.wrap(rangeKey, length - 8, 8);
  final int dataIdLength = metadataBuf.getInt();
  final int numberOfDuplicates = metadataBuf.getInt();

  final ByteBuffer buf = ByteBuffer.wrap(rangeKey, 0, length - 16);
  final byte[] sortKey = new byte[length - 16 - 2 - dataIdLength];
  final byte[] dataId = new byte[dataIdLength];

  // Range key (row ID) = adapterId + sortKey + dataId
  final byte[] internalAdapterIdBytes = new byte[2];
  buf.get(internalAdapterIdBytes);
  final short internalAdapterId = ByteArrayUtils.byteArrayToShort(internalAdapterIdBytes);
  buf.get(sortKey);
  buf.get(dataId);

  return new GeoWaveKeyImpl(
      dataId,
      internalAdapterId,
      Arrays.areEqual(DynamoDBUtils.EMPTY_PARTITION_KEY, partitionKey) ? new byte[0]
          : partitionKey,
      DynamoDBUtils.decodeSortableBase64(sortKey),
      numberOfDuplicates);
}
 
Example 6
Source File: Address.java    From bop-bitcoin-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals (Object obj)
{
	if ( this == obj )
	{
		return true;
	}
	if ( obj == null || getClass () != obj.getClass () )
	{
		return false;
	}
	return Arrays.areEqual (bytes, ((Address) obj).bytes) && type == ((Address) obj).type;
}
 
Example 7
Source File: ExtendedKey.java    From bushido-java-core with GNU General Public License v3.0 5 votes vote down vote up
public static ExtendedKey parse(String serialized, boolean compressed) throws Exception {
    byte[] data = ByteUtil.fromBase58WithChecksum(serialized);
    if (data.length != 78)
    {
        throw new Exception("Invalid extended key");
    }
    byte[] type = Arrays.copyOf(data, 4);
    boolean hasPrivate;
    if (Arrays.areEqual(type, xprv))
    {
        hasPrivate = true;
    }
    else if (Arrays.areEqual(type, xpub))
    {
        hasPrivate = false;
    }
    else
    {
        throw new Exception("Invalid or unsupported key type");
    }
    int depth = data[4] & 0xff;
    int parentFingerprint = data[5] & 0xff;
    parentFingerprint <<= 8;
    parentFingerprint |= data[6] & 0xff;
    parentFingerprint <<= 8;
    parentFingerprint |= data[7] & 0xff;
    parentFingerprint <<= 8;
    parentFingerprint |= data[8] & 0xff;
    int sequence = data[9] & 0xff;
    sequence <<= 8;
    sequence |= data[10] & 0xff;
    sequence <<= 8;
    sequence |= data[11] & 0xff;
    sequence <<= 8;
    sequence |= data[12] & 0xff;
    final byte[] chainCode = Arrays.copyOfRange(data, 13, 13 + 32);
    final byte[] keyBytes = Arrays.copyOfRange(data, 13 + 32, data.length);
    final ECKey ecKey = new ECKey(keyBytes, compressed, hasPrivate);
    return new ExtendedKey(chainCode, sequence, depth, parentFingerprint, ecKey);
}
 
Example 8
Source File: ExtendedKey.java    From bushido-java-core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (obj instanceof ExtendedKey)
    {
        return ecKey.equals(((ExtendedKey) obj).ecKey)
                && Arrays.areEqual(chainCode, ((ExtendedKey) obj).chainCode)
                && depth == ((ExtendedKey) obj).depth
                && parentFingerprint == ((ExtendedKey) obj).parentFingerprint
                && sequence == ((ExtendedKey) obj).sequence;
    }
    return false;
}
 
Example 9
Source File: ECKey.java    From bushido-java-core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {

    if (obj instanceof ECKey) {
        return Arrays.areEqual(((ECKey) obj).getPrivate(), this.getPrivate())
                && Arrays.areEqual(((ECKey) obj).getPublic(), this.getPublic())
                && Arrays.areEqual(((ECKey) obj).getPublicKeyHash(), this.getPublicKeyHash())
                && ((ECKey) obj).isCompressed() == this.isCompressed();

    }
    return false;
}
 
Example 10
Source File: BuilderUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkHash(byte[] blobHashValue, byte[] decompressedBlob) throws InvalidBlobContentConnectorException, TechnicalConnectorException {
   try {
      byte[] calculatedHashValue = buildHash(decompressedBlob);
      if (!Arrays.areEqual(blobHashValue, calculatedHashValue)) {
         String blobHashAsString = blobHashValue != null ? new String(Base64.encode(blobHashValue)) : "";
         String calculatedHashAsString = calculatedHashValue != null ? new String(Base64.encode(calculatedHashValue)) : "";
         throw new InvalidBlobContentConnectorException(InvalidBlobContentConnectorExceptionValues.HASH_VALUES_DIFFERENT, (Blob)null, decompressedBlob, new Object[]{blobHashAsString, calculatedHashAsString});
      }
   } catch (NoSuchAlgorithmException var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var5, new Object[]{var5.getMessage()});
   }
}
 
Example 11
Source File: FileStreamWriter.java    From InflatableDonkey with MIT License 5 votes vote down vote up
static boolean testSignature(Digest digest, byte[] signature) {
    byte[] out = signature(digest);
    boolean match = Arrays.areEqual(out, signature);
    if (match) {
        logger.debug("-- testSignature() - positive match out: 0x{} target: 0x{}",
                Hex.toHexString(out), Hex.toHexString(signature));
    } else {

        logger.warn("-- testSignature() - negative match out: 0x{} target: 0x{}",
                Hex.toHexString(out), Hex.toHexString(signature));
    }
    return match;
}
 
Example 12
Source File: BuilderUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkHash(byte[] blobHashValue, byte[] decompressedBlob) throws InvalidBlobContentConnectorException, TechnicalConnectorException {
   try {
      byte[] calculatedHashValue = buildHash(decompressedBlob);
      if (!Arrays.areEqual(blobHashValue, calculatedHashValue)) {
         String blobHashAsString = blobHashValue != null ? new String(Base64.encode(blobHashValue)) : "";
         String calculatedHashAsString = calculatedHashValue != null ? new String(Base64.encode(calculatedHashValue)) : "";
         throw new InvalidBlobContentConnectorException(InvalidBlobContentConnectorExceptionValues.HASH_VALUES_DIFFERENT, (Blob)null, decompressedBlob, new Object[]{blobHashAsString, calculatedHashAsString});
      }
   } catch (NoSuchAlgorithmException var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var5, new Object[]{var5.getMessage()});
   }
}
 
Example 13
Source File: BuilderUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkHash(byte[] blobHashValue, byte[] decompressedBlob) throws InvalidBlobContentConnectorException, TechnicalConnectorException {
   try {
      byte[] calculatedHashValue = buildHash(decompressedBlob);
      if (!Arrays.areEqual(blobHashValue, calculatedHashValue)) {
         String blobHashAsString = blobHashValue != null ? new String(Base64.encode(blobHashValue)) : "";
         String calculatedHashAsString = calculatedHashValue != null ? new String(Base64.encode(calculatedHashValue)) : "";
         throw new InvalidBlobContentConnectorException(InvalidBlobContentConnectorExceptionValues.HASH_VALUES_DIFFERENT, (Blob)null, decompressedBlob, new Object[]{blobHashAsString, calculatedHashAsString});
      }
   } catch (NoSuchAlgorithmException var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var5, new Object[]{var5.getMessage()});
   }
}
 
Example 14
Source File: Address.java    From WalletCordova with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean equals (Object obj)
{
	if ( this == obj )
	{
		return true;
	}
	if ( obj == null || getClass () != obj.getClass () )
	{
		return false;
	}
	return Arrays.areEqual (bytes, ((Address) obj).bytes) && type == ((Address) obj).type;
}
 
Example 15
Source File: BuilderUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkHash(byte[] blobHashValue, byte[] decompressedBlob) throws InvalidBlobContentConnectorException, TechnicalConnectorException {
   try {
      byte[] calculatedHashValue = buildHash(decompressedBlob);
      if (!Arrays.areEqual(blobHashValue, calculatedHashValue)) {
         String blobHashAsString = blobHashValue != null ? new String(Base64.encode(blobHashValue)) : "";
         String calculatedHashAsString = calculatedHashValue != null ? new String(Base64.encode(calculatedHashValue)) : "";
         throw new InvalidBlobContentConnectorException(InvalidBlobContentConnectorExceptionValues.HASH_VALUES_DIFFERENT, (Blob)null, decompressedBlob, new Object[]{blobHashAsString, calculatedHashAsString});
      }
   } catch (NoSuchAlgorithmException var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var5, new Object[]{var5.getMessage()});
   }
}
 
Example 16
Source File: ServerConfigurationDialog.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public ServerConfiguration getConfiguration() {
    // Use the Copy Constructor to return a Copy to be able to undo changes even after the configuration has changed
    ServerConfiguration ret = serverConfiguration != null ? new ServerConfiguration(serverConfiguration) : new ServerConfiguration(null);
    ret.setName(name.getText());
    ret.setHost(host.getText());
    ret.setDescription(description.getText());
    DefaultMode defaultMode = DefaultMode.none;
    if(defaultRunConfiguration.isSelected()) {
        defaultMode = DefaultMode.run;
    } else if(defaultDebugConfiguration.isSelected()) {
        defaultMode = DefaultMode.debug;
    }
    ret.setDefaultMode(defaultMode);
    ret.setBuildWithMaven(buildWithMaven.isSelected());
    ret.setMavenBuildTimeoutInSeconds(UIUtil.obtainInteger(mavenBuildTimeoutInSeconds, ServerConfiguration.DEFAULT_MAVEN_BUILD_TIME_OUT_IN_SECONDS));
    ret.setConnectionPort(UIUtil.obtainInteger(connectionPort, 0));
    ret.setConnectionDebugPort(UIUtil.obtainInteger(connectionDebugPort, 0));
    ret.setUserName(connectionUserName.getText());
    char[] password = connectionPassword.getPassword();
    if(password == null) { password = new char[0]; }
    // If it is the dummy password then ignore it
    if(!Arrays.areEqual(password, DUMMY_PWD.toCharArray())) {
        ret.setPassword(password);
    }
    ret.setContextPath(connectionContextPath.getText());
    ret.setStartConnectionTimeoutInSeconds(UIUtil.obtainInteger(startConnectionTimeout, -1));
    ret.setStopConnectionTimeoutInSeconds(UIUtil.obtainInteger(stopConnectionTimeout, -1));
    ServerConfiguration.PublishType publishType =
        neverAutomaticallyPublishContentRadioButton.isSelected() ? ServerConfiguration.PublishType.never :
            automaticallyPublishOnChangeRadioButton.isSelected() ? ServerConfiguration.PublishType.automaticallyOnChange :
                automaticallyPublishOnBuildRadioButton.isSelected() ? ServerConfiguration.PublishType.automaticallyOnBuild :
                    null;
    ret.setPublishType(publishType);
    ServerConfiguration.InstallationType installationType =
        installBundlesViaBundleRadioButton.isSelected() ? ServerConfiguration.InstallationType.installViaBundleUpload :
            installBundlesDirectlyFromRadioButton.isSelected() ? ServerConfiguration.InstallationType.installViaBundleUpload :
                    null;
    ret.setInstallationType(installationType);

    return ret;
}
 
Example 17
Source File: AbstractStoresTest.java    From alfresco-simple-content-stores with Apache License 2.0 4 votes vote down vote up
/**
 * Checks whether the content in two files matches.
 *
 * @param fileA
 *            the first of the two files
 * @param fileB
 *            the second of the two files
 * @return {@code true} if the files match, {@code false} otherwise
 */
protected static boolean contentMatches(final Path fileA, final Path fileB) throws IOException
{
    boolean matches;

    try (InputStream isA = Files.newInputStream(fileA))
    {
        try (InputStream isB = Files.newInputStream(fileB))
        {
            final byte[] buffA = new byte[4096];
            final byte[] buffB = new byte[4096];
            int offset = 0;

            matches = true;
            while (matches)
            {
                final int bytesReadA = isA.read(buffA);
                final int bytesReadB = isB.read(buffB);

                if (bytesReadA != bytesReadB)
                {
                    matches = false;
                    if (!matches)
                    {
                        LOGGER.debug(
                                "contentMatches failed due to difference in length - read {} expected vs {} bytes in slice starting at position {}",
                                bytesReadA, bytesReadB, offset);
                    }
                }
                else if (bytesReadA != -1)
                {
                    // note: don't have to care about equals check including bytes between bytesRead and length
                    // (any left over bytes from previous read would be identical in both buffers)
                    matches = Arrays.areEqual(buffA, buffB);

                    if (!matches)
                    {
                        LOGGER.debug(
                                "contentMatches failed due to difference in content slice starting at position {} and with a length of {}",
                                offset, bytesReadA);
                    }

                    offset += bytesReadA;
                }
                else
                {
                    break;
                }
            }
        }
    }
    return matches;
}
 
Example 18
Source File: ContractHelper.java    From nuls-v2 with MIT License 4 votes vote down vote up
public void dealNrc20Events(int chainId, byte[] newestStateRoot, Transaction tx, ContractResult contractResult, ContractAddressInfoPo po) {
    if (po == null) {
        return;
    }
    try {
        List<String> events = contractResult.getEvents();
        int size = events.size();
        // 目前只处理Transfer事件, 为了刷新账户的token余额
        String event;
        ContractAddressInfoPo contractAddressInfo;
        if (events != null && size > 0) {
            for (int i = 0; i < size; i++) {
                event = events.get(i);
                // 按照NRC20标准,TransferEvent事件中第一个参数是转出地址-from,第二个参数是转入地址-to, 第三个参数是金额
                ContractTokenTransferInfoPo tokenTransferInfoPo = ContractUtil.convertJsonToTokenTransferInfoPo(chainId, event);
                if (tokenTransferInfoPo == null) {
                    continue;
                }
                String contractAddress = tokenTransferInfoPo.getContractAddress();
                if (StringUtils.isBlank(contractAddress)) {
                    continue;
                }
                if (!AddressTool.validAddress(chainId, contractAddress)) {
                    continue;
                }
                byte[] contractAddressBytes = AddressTool.getAddress(contractAddress);
                if (Arrays.areEqual(po.getContractAddress(), contractAddressBytes)) {
                    contractAddressInfo = po;
                } else {
                    Result<ContractAddressInfoPo> contractAddressInfoResult = this.getContractAddressInfo(chainId, contractAddressBytes);
                    contractAddressInfo = contractAddressInfoResult.getData();
                }

                if (contractAddressInfo == null) {
                    continue;
                }
                // 事件不是NRC20合约的事件
                if (!contractAddressInfo.isNrc20()) {
                    continue;
                }
                byte[] txHashBytes;
                byte[] from = tokenTransferInfoPo.getFrom();
                byte[] to = tokenTransferInfoPo.getTo();
                tokenTransferInfoPo.setName(contractAddressInfo.getNrc20TokenName());
                tokenTransferInfoPo.setSymbol(contractAddressInfo.getNrc20TokenSymbol());
                tokenTransferInfoPo.setDecimals(contractAddressInfo.getDecimals());
                tokenTransferInfoPo.setTime(tx.getTime());
                tokenTransferInfoPo.setBlockHeight(tx.getBlockHeight());
                txHashBytes = tx.getHash().getBytes();
                tokenTransferInfoPo.setTxHash(txHashBytes);
                tokenTransferInfoPo.setStatus((byte) (contractResult.isSuccess() ? 1 : 2));

                if (from != null) {
                    this.refreshTokenBalance(chainId, newestStateRoot, tx.getBlockHeight(), contractAddressInfo, AddressTool.getStringAddressByBytes(from), contractAddress);
                    this.saveTokenTransferInfo(chainId, from, txHashBytes, new VarInt(i).encode(), tokenTransferInfoPo);
                }
                if (to != null) {
                    this.refreshTokenBalance(chainId, newestStateRoot, tx.getBlockHeight(), contractAddressInfo, AddressTool.getStringAddressByBytes(to), contractAddress);
                    this.saveTokenTransferInfo(chainId, to, txHashBytes, new VarInt(i).encode(), tokenTransferInfoPo);
                }
            }
        }
    } catch (Exception e) {
        Log.warn("contract event parse error.", e);
        throw new RuntimeException(e);
    }
}
 
Example 19
Source File: Block.java    From nuls-v2 with MIT License 4 votes vote down vote up
public boolean isEqual(Block block) {
    return Arrays.areEqual(this.getHash(), block.getHash());
}
 
Example 20
Source File: ExtendedKey.java    From bop-bitcoin-client with Apache License 2.0 4 votes vote down vote up
public static ExtendedKey parse (String serialized) throws ValidationException
{
	byte[] data = ByteUtils.fromBase58WithChecksum (serialized);
	if ( data.length != 78 )
	{
		throw new ValidationException ("invalid extended key");
	}
	byte[] type = Arrays.copyOf (data, 4);
	boolean hasPrivate;
	if ( Arrays.areEqual (type, xprv) || Arrays.areEqual (type, tprv) )
	{
		hasPrivate = true;
	}
	else if ( Arrays.areEqual (type, xpub) || Arrays.areEqual (type, tpub) )
	{
		hasPrivate = false;
	}
	else
	{
		throw new ValidationException ("invalid magic number for an extended key");
	}

	int depth = data[4] & 0xff;

	int parent = data[5] & 0xff;
	parent <<= 8;
	parent |= data[6] & 0xff;
	parent <<= 8;
	parent |= data[7] & 0xff;
	parent <<= 8;
	parent |= data[8] & 0xff;

	int sequence = data[9] & 0xff;
	sequence <<= 8;
	sequence |= data[10] & 0xff;
	sequence <<= 8;
	sequence |= data[11] & 0xff;
	sequence <<= 8;
	sequence |= data[12] & 0xff;

	byte[] chainCode = Arrays.copyOfRange (data, 13, 13 + 32);
	byte[] pubOrPriv = Arrays.copyOfRange (data, 13 + 32, data.length);
	Key key;
	if ( hasPrivate )
	{
		key = new ECKeyPair (new BigInteger (1, pubOrPriv), true);
	}
	else
	{
		key = new ECPublicKey (pubOrPriv, true);
	}
	return new ExtendedKey (key, chainCode, depth, parent, sequence);
}