Java Code Examples for com.google.protobuf.ByteString#equals()
The following examples show how to use
com.google.protobuf.ByteString#equals() .
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: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
/** * Removes the uuid from the full members of a group. * <p> * Generally not expected to have to do this, just in the case of leaving a group where you cannot * get the new group state as you are not in the group any longer. */ public static DecryptedGroup removeMember(DecryptedGroup group, UUID uuid, int revision) { DecryptedGroup.Builder builder = DecryptedGroup.newBuilder(group); ByteString uuidString = UuidUtil.toByteString(uuid); boolean removed = false; ArrayList<DecryptedMember> decryptedMembers = new ArrayList<>(builder.getMembersList()); Iterator<DecryptedMember> membersList = decryptedMembers.iterator(); while (membersList.hasNext()) { if (uuidString.equals(membersList.next().getUuid())) { membersList.remove(); removed = true; } } if (removed) { return builder.clearMembers() .addAllMembers(decryptedMembers) .setRevision(revision) .build(); } else { return group; } }
Example 2
Source File: GroupsV2UpdateMessageProducer.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void describeMemberRemovals(@NonNull DecryptedGroupChange change, @NonNull List<String> updates) { boolean editorIsYou = change.getEditor().equals(selfUuidBytes); for (ByteString member : change.getDeleteMembersList()) { boolean removedMemberIsYou = member.equals(selfUuidBytes); if (editorIsYou) { if (removedMemberIsYou) { updates.add(context.getString(R.string.MessageRecord_you_left_the_group)); } else { updates.add(context.getString(R.string.MessageRecord_you_removed_s, describe(member))); } } else { if (removedMemberIsYou) { updates.add(context.getString(R.string.MessageRecord_s_removed_you_from_the_group, describe(change.getEditor()))); } else { if (member.equals(change.getEditor())) { updates.add(context.getString(R.string.MessageRecord_s_left_the_group, describe(member))); } else { updates.add(context.getString(R.string.MessageRecord_s_removed_s, describe(change.getEditor()), describe(member))); } } } } }
Example 3
Source File: GroupsV2UpdateMessageProducer.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void describePromotePending(@NonNull DecryptedGroupChange change, @NonNull List<String> updates) { boolean editorIsYou = change.getEditor().equals(selfUuidBytes); for (DecryptedMember newMember : change.getPromotePendingMembersList()) { ByteString uuid = newMember.getUuid(); boolean newMemberIsYou = uuid.equals(selfUuidBytes); if (editorIsYou) { if (newMemberIsYou) { updates.add(context.getString(R.string.MessageRecord_you_accepted_invite)); } else { updates.add(context.getString(R.string.MessageRecord_you_added_invited_member_s, describe(uuid))); } } else { if (newMemberIsYou) { updates.add(context.getString(R.string.MessageRecord_s_added_you, describe(change.getEditor()))); } else { if (uuid.equals(change.getEditor())) { updates.add(context.getString(R.string.MessageRecord_s_accepted_invite, describe(uuid))); } else { updates.add(context.getString(R.string.MessageRecord_s_added_invited_member_s, describe(change.getEditor()), describe(uuid))); } } } } }
Example 4
Source File: ScanIterator.java From client-java with Apache License 2.0 | 6 votes |
ScanIterator( TiConfiguration conf, RegionStoreClientBuilder builder, ByteString startKey, ByteString endKey, int limit) { this.startKey = requireNonNull(startKey, "start key is null"); if (startKey.isEmpty()) { throw new IllegalArgumentException("start key cannot be empty"); } this.endKey = Key.toRawKey(requireNonNull(endKey, "end key is null")); this.hasEndKey = !endKey.equals(ByteString.EMPTY); this.limit = limit; this.conf = conf; this.builder = builder; }
Example 5
Source File: TiclStateManager.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether the digest in {@code state} is correct. */ private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) { Sha1DigestFunction digester = new Sha1DigestFunction(); digester.update(state.getState().toByteArray()); ByteString computedDigest = ByteString.copyFrom(digester.getDigest()); if (!computedDigest.equals(state.getDigest())) { logger.warning("Android Ticl state digest mismatch; computed %s for %s", computedDigest, state); return false; } return true; }
Example 6
Source File: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public static Optional<DecryptedMember> findMemberByUuid(Collection<DecryptedMember> members, UUID uuid) { ByteString uuidBytes = UuidUtil.toByteString(uuid); for (DecryptedMember member : members) { if (uuidBytes.equals(member.getUuid())) { return Optional.of(member); } } return Optional.absent(); }
Example 7
Source File: TiclStateManager.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether the digest in {@code state} is correct. */ private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) { Sha1DigestFunction digester = new Sha1DigestFunction(); digester.update(state.getState().toByteArray()); ByteString computedDigest = ByteString.copyFrom(digester.getDigest()); if (!computedDigest.equals(state.getDigest())) { logger.warning("Android Ticl state digest mismatch; computed %s for %s", computedDigest, state); return false; } return true; }
Example 8
Source File: Duck32.java From snowblossom with Apache License 2.0 | 5 votes |
private static void validateChecksum(String label, ByteString data, ByteString checksum) throws ValidationException { ByteString expected = applyChecksum(label, data); ByteString have = data.concat(checksum); if (!expected.equals(have)) throw new ValidationException("Checksum mismatch"); }
Example 9
Source File: HashedTrie.java From snowblossom with Apache License 2.0 | 5 votes |
public boolean mergeIfNewRoot(ByteString old_root, Map<ByteString, ByteString> updates, ByteString expected_new_root) { TrieDBBuffered db = new TrieDBBuffered(basedb); TrieNode root = db.load(old_root); ByteString answer = mergeNode(db, root, updates).getHash(); if (answer.equals(expected_new_root)) { System.out.println("Commiting new UTXO root: " + HashUtils.getHexString(answer)); db.commit(); return true; } return false; }
Example 10
Source File: WitnessController.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
public boolean validateWitnessSchedule(ByteString witnessAddress, long timeStamp) { //to deal with other condition later if (manager.getDynamicPropertiesStore().getLatestBlockHeaderNumber() == 0) { return true; } long blockAbSlot = getAbSlotAtTime(timeStamp); long headBlockAbSlot = getAbSlotAtTime( manager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp()); if (blockAbSlot <= headBlockAbSlot) { logger.warn("blockAbSlot is equals with headBlockAbSlot[" + blockAbSlot + "]"); return false; } long slot = getSlotAtTime(timeStamp); final ByteString scheduledWitness = getScheduledWitness(slot); if (!scheduledWitness.equals(witnessAddress)) { logger.warn( "Witness is out of order, scheduledWitness[{}],blockWitnessAddress[{}],blockTimeStamp[{}],slot[{}]", ByteArray.toHexString(scheduledWitness.toByteArray()), ByteArray.toHexString(witnessAddress.toByteArray()), new DateTime(timeStamp), slot); return false; } logger.debug("Validate witnessSchedule successfully,scheduledWitness:{}", ByteArray.toHexString(witnessAddress.toByteArray())); return true; }
Example 11
Source File: Helper.java From julongchain with Apache License 2.0 | 5 votes |
private static void validatePvtdata(Transaction tx, TxPvtData pvtData)throws LedgerException{ if(pvtData.getWriteSet() == null){ return; } for(Rwset.NsPvtReadWriteSet nsPvtRwSet : pvtData.getWriteSet().getNsPvtRwsetList()){ for(Rwset.CollectionPvtReadWriteSet collPvtdata : nsPvtRwSet.getCollectionPvtRwsetList()){ //TODO SM3 hash ByteString collPvtdataHash = ByteString.copyFrom(Util.getHashBytes(collPvtdata.getRwset().toByteArray())); ByteString hashInPubdata = tx.retrieveHash(nsPvtRwSet.getNamespace(), collPvtdata.getCollectionName()); if(!collPvtdataHash.equals(hashInPubdata)){ throw new LedgerException("Hash of pvt data mismatch corresponding hash in pub data"); } } } }
Example 12
Source File: GroupProtoUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public static boolean isMember(@NonNull UUID uuid, @NonNull List<DecryptedMember> membersList) { ByteString uuidBytes = UuidUtil.toByteString(uuid); for (DecryptedMember member : membersList) { if (uuidBytes.equals(member.getUuid())) { return true; } } return false; }
Example 13
Source File: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static int findPendingIndexByUuid(List<DecryptedPendingMember> members, ByteString uuid) { for (int i = 0; i < members.size(); i++) { DecryptedPendingMember member = members.get(i); if (uuid.equals(member.getUuid())) { return i; } } return -1; }
Example 14
Source File: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static int findPendingIndexByUuidCipherText(List<DecryptedPendingMember> members, ByteString cipherText) { for (int i = 0; i < members.size(); i++) { DecryptedPendingMember member = members.get(i); if (cipherText.equals(member.getUuidCipherText())) { return i; } } return -1; }
Example 15
Source File: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public static Optional<DecryptedPendingMember> findPendingByUuid(Collection<DecryptedPendingMember> members, UUID uuid) { ByteString uuidBytes = UuidUtil.toByteString(uuid); for (DecryptedPendingMember member : members) { if (uuidBytes.equals(member.getUuid())) { return Optional.of(member); } } return Optional.absent(); }
Example 16
Source File: DecryptedGroupUtil.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private static int indexOfUuid(List<DecryptedMember> memberList, ByteString uuid) { for (int i = 0; i < memberList.size(); i++) { if(uuid.equals(memberList.get(i).getUuid())) return i; } return -1; }
Example 17
Source File: Validation.java From snowblossom with Apache License 2.0 | 4 votes |
public static boolean checkProof(SnowPowProof proof, ByteString expected_merkle_root, long snow_field_size) { long target_index = proof.getWordIdx(); long word_count = snow_field_size / SnowMerkle.HASH_LEN_LONG; if (target_index < 0) return false; if (target_index >= word_count) return false; MessageDigest md; try { md = MessageDigest.getInstance(Globals.SNOW_MERKLE_HASH_ALGO); } catch(java.security.NoSuchAlgorithmException e) { throw new RuntimeException( e ); } LinkedList<ByteString> stack = new LinkedList<>(); stack.addAll(proof.getMerkleComponentList()); ByteString current_hash = stack.poll(); if (current_hash == null) return false; long start = target_index; long end = target_index; long dist = 1; // To visualize this, take the recursive getInnerProof() below // and do it backwards while ((stack.size() > 0) && (end <= word_count)) { dist *= 2; start = start - (start % dist); end = start + dist; long mid = (start + end) / 2; ByteString left = null; ByteString right = null; if (target_index < mid) { left = current_hash; right = stack.poll(); } else { left = stack.poll(); right = current_hash; } md.update(left.toByteArray()); md.update(right.toByteArray()); byte[] hash = md.digest(); current_hash = ByteString.copyFrom(hash); } // We expect to end with our sublist being the entire file // so we check to avoid someone passing off an intermediate node // as a merkle tree member if (start != 0) return false; if (end != word_count) return false; if (current_hash.equals(expected_merkle_root)) return true; return false; }