Example usage for org.bouncycastle.pqc.math.linearalgebra ByteUtils concatenate

List of usage examples for org.bouncycastle.pqc.math.linearalgebra ByteUtils concatenate

Introduction

In this page you can find the example usage for org.bouncycastle.pqc.math.linearalgebra ByteUtils concatenate.

Prototype

public static byte[] concatenate(byte[] x1, byte[] x2) 

Source Link

Document

Concatenate two byte arrays.

Usage

From source file:co.rsk.trie.TrieImpl.java

License:Open Source License

/**
 * put key with associated value, returning a new NewTrie
 *
 * @param key   key to be updated/* w  w w  .j a v a  2s.  c  o m*/
 * @param length    total length of key
 * @param keyPosition  current position of the key to be processed
 * @param value     associated value
 *
 * @return the new NewTrie containing the tree with the new key value association
 *
 */
private TrieImpl put(byte[] key, int length, int keyPosition, byte[] value) {
    TrieImpl trie = this.internalPut(key, length, keyPosition, value);

    // the following code coalesces nodes if needed for delete operation

    // it's null or it is not a delete operation
    if (trie == null || value != null) {
        return trie;
    }

    if (isEmptyTrie(trie.value, trie.nodes, trie.hashes)) {
        return null;
    }

    // only coalesce if node has only one child and no value
    if (trie.value != null || trie.getNodeCount() != 1) {
        return trie;
    }

    TrieImpl firstChild = null;
    int firstChildPosition = 0;

    for (int k = 0; firstChild == null && k < ARITY; k++) {
        firstChildPosition = k;
        firstChild = (TrieImpl) trie.retrieveNode(k);
    }

    if (firstChild == null) {
        throw new NullPointerException();
    }

    byte[] trieSharedPath;
    byte[] positionPath = new byte[] { (byte) firstChildPosition };

    if (trie.sharedPathLength == 0) {
        trieSharedPath = positionPath;
    } else {
        trieSharedPath = ByteUtils
                .concatenate(PathEncoder.decode(trie.encodedSharedPath, trie.sharedPathLength), positionPath);
    }

    byte[] newSharedPath;

    if (firstChild.sharedPathLength == 0) {
        newSharedPath = trieSharedPath;
    } else {
        byte[] childSharedPath = PathEncoder.decode(firstChild.encodedSharedPath, firstChild.sharedPathLength);
        newSharedPath = ByteUtils.concatenate(trieSharedPath, childSharedPath);
    }

    TrieImpl newTrie = (TrieImpl) firstChild.cloneTrie();
    newTrie.sharedPathLength = newSharedPath.length;
    newTrie.encodedSharedPath = PathEncoder.encode(newSharedPath);

    return newTrie;
}

From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkChecksums.java

License:Open Source License

public static Optional<byte[]> checksum(int type, byte[] data) {
    if (type != 1) {
        logger.warn("-- checksum() - checksum type not supported: {}", type);
        return Optional.empty();
    }/*from w ww  .j  a v a2s  .  com*/

    byte[] hashType1 = hashType1(data);
    byte[] checksum = ByteUtils.concatenate(new byte[] { 0x01 }, hashType1);
    return Optional.of(checksum);
}