net.openhft.chronicle.bytes.NativeBytesStore Java Examples
The following examples show how to use
net.openhft.chronicle.bytes.NativeBytesStore.
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: QueueSingleThreadedJLBHBenchmark.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Override public void init(JLBH jlbh) { IOTools.deleteDirWithFiles("replica", 10); Byteable byteable = (Byteable) datum; long capacity = byteable.maxSize(); byteable.bytesStore(NativeBytesStore.nativeStore(capacity), 0, capacity); datumBytes = ((Byteable) datum).bytesStore(); datumWrite = datumBytes.bytesForWrite(); sourceQueue = single("replica").build(); sinkQueue = single("replica").build(); appender = sourceQueue.acquireAppender(); tailer = sinkQueue.createTailer(); this.jlbh = jlbh; }
Example #2
Source File: PacketHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public boolean put(final MdpPacket mdpPacket, final long seqNum) { if (seqNumHolder < seqNum) { seqNumHolder = seqNum; packetSize = mdpPacket.getPacketSize(); if (store.capacity() < packetSize) { store.release(); store = NativeBytesStore.nativeStoreWithFixedCapacity(packetSize); } mdpPacket.buffer().copyTo(this.store); return true; } else { logger.trace("MDP Packet #{} data was not stored because too old", seqNum); return false; } }
Example #3
Source File: IncrementalRefreshHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public boolean put(final IncrementalRefreshQueueEntry queueEntry, final long rptSeqNum) { if (rptSeqNumHolder < rptSeqNum) { rptSeqNumHolder = rptSeqNum; final MdpGroupEntry incrEntry = queueEntry.groupEntry; this.entrySize = incrEntry.getBlockLength(); this.matchEventIndicator = queueEntry.matchEventIndicator; this.incrPcktSeqNum = queueEntry.incrPcktSeqNum; if (store.capacity() < entrySize) { store.release(); store = NativeBytesStore.nativeStoreWithFixedCapacity(entrySize); } incrEntry.buffer().copyTo(incrEntry.getAbsoluteEntryOffset(), this.store, entrySize); this.sbeGroupType = incrEntry.getSbeGroupType(); return true; } else { if(logger.isTraceEnabled()) { logger.trace("Incremental Refresh Entry #{} data was not stored because too old", rptSeqNum); } return false; } }
Example #4
Source File: VanillaChronicleHash.java From Chronicle-Map with Apache License 2.0 | 6 votes |
private void mapTierBulksMapped(int upToBulkIndex) throws IOException { int firstBulkToMapIndex = tierBulkOffsets.size(); int bulksToMap = upToBulkIndex + 1 - firstBulkToMapIndex; long mapSize = bulksToMap * tierBulkSizeInBytes; long mappingOffsetInFile, firstBulkToMapOffsetWithinMapping; long firstBulkToMapOffset = bulkOffset(firstBulkToMapIndex); if (OS.mapAlign(firstBulkToMapOffset) == firstBulkToMapOffset) { mappingOffsetInFile = firstBulkToMapOffset; firstBulkToMapOffsetWithinMapping = 0; } else { // If the bulk was allocated on OS with 4K mapping granularity (linux) and we // are mapping it in OS with 64K mapping granularity (windows), we might need to // start the mapping earlier than the first tier to map actually starts mappingOffsetInFile = OS.mapAlign(firstBulkToMapOffset) - OS.mapAlignment(); firstBulkToMapOffsetWithinMapping = firstBulkToMapOffset - mappingOffsetInFile; // Now might need to have bigger mapSize mapSize += firstBulkToMapOffsetWithinMapping; } // mapping by hand, because MappedFile/MappedBytesStore doesn't allow to create a BS // which starts not from the beginning of the file, but has start() of 0 NativeBytesStore extraStore = map(mapSize, mappingOffsetInFile); appendBulkData(firstBulkToMapIndex, upToBulkIndex, extraStore, firstBulkToMapOffsetWithinMapping); }
Example #5
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 6 votes |
@Test public void testMultiPart() { BytesStore message1 = NativeBytesStore.from("Message part1"); BytesStore message2 = NativeBytesStore.from("Message part2"); BytesStore message3 = NativeBytesStore.from("Message part3"); Signature.KeyPair keys = Signature.KeyPair.deterministic(123); Signature.MultiPart multi = new Signature.MultiPart(); multi.add(message1); multi.add(message2); multi.add(message3); BytesStore signature = multi.sign(keys.secretKey); assertEquals( "FE7EBF26E92709DB6DC2953F93E757883627CA0956685392E2173774A051ABF5" + "12CB6791D42F13F5C672B226731EF9263284502BC64BD6FDC8858B4BB49CA006", DatatypeConverter.printHexBinary(signature.toByteArray())); Signature.MultiPart recv = new Signature.MultiPart(); recv.add(message1); recv.add(message2); recv.add(message3); recv.verify(signature, keys.publicKey); }
Example #6
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 6 votes |
@Test public void testMultiPart2() { BytesStore message1 = NativeBytesStore.from("Message part1"); BytesStore message2 = NativeBytesStore.from("Message part2"); BytesStore message3 = NativeBytesStore.from("Message part3"); Signature.KeyPair keys = Signature.KeyPair.deterministic(123); Signature.MultiPart multi = new Signature.MultiPart(); multi.add(message1); multi.add(message2); multi.add(message3); BytesStore signature = multi.sign(keys.secretKey.store); assertEquals( "FE7EBF26E92709DB6DC2953F93E757883627CA0956685392E2173774A051ABF5" + "12CB6791D42F13F5C672B226731EF9263284502BC64BD6FDC8858B4BB49CA006", DatatypeConverter.printHexBinary(signature.toByteArray())); Signature.MultiPart recv = new Signature.MultiPart(); recv.add(message1); recv.add(message2); recv.add(message3); recv.verify(signature, keys.publicKey.store); }
Example #7
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 6 votes |
@Test public void bulkEncryptDecrypt() { EasyBox.KeyPair alice = EasyBox.KeyPair.generate(); EasyBox.KeyPair bob = EasyBox.KeyPair.generate(); EasyBox.Nonce nonce = EasyBox.Nonce.generate(); BytesStore message = NativeBytesStore.from("Hello World, this is a short message for testing purposes"); int runs = 10000; for (int t = 0; t < 3; t++) { BytesStore cipher = EasyBox.encrypt(message, nonce, bob.publicKey, alice.secretKey); BytesStore clear = EasyBox.decrypt(cipher, nonce, alice.publicKey, bob.secretKey); assertTrue(Arrays.equals(message.toByteArray(), clear.toByteArray())); message = cipher; nonce.next(); } }
Example #8
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 6 votes |
@Test public void bulkEncryptDecryptShared() { EasyBox.KeyPair alice = EasyBox.KeyPair.generate(); EasyBox.KeyPair bob = EasyBox.KeyPair.generate(); EasyBox.SharedKey shared = EasyBox.SharedKey.precalc(alice.publicKey, bob.secretKey); EasyBox.Nonce nonce = EasyBox.Nonce.generate(); BytesStore message = NativeBytesStore.from("Hello World, this is a short message for testing purposes"); int runs = 10000; for (int t = 0; t < 3; t++) { BytesStore cipher = EasyBox.encryptShared(message, nonce, shared); BytesStore clear = EasyBox.decryptShared(cipher, nonce, shared); assertTrue(Arrays.equals(message.toByteArray(), clear.toByteArray())); message = cipher; nonce.next(); } }
Example #9
Source File: IntValueMapTest.java From Chronicle-Map with Apache License 2.0 | 6 votes |
@Test public void test() throws IOException { try (final ChronicleMap<IntValue, CharSequence> map = ChronicleMapBuilder .of(IntValue.class, CharSequence.class) .averageValue("test") .entries(20000).create()) { IntValue value = Values.newNativeReference(IntValue.class); ((Byteable) value).bytesStore(NativeBytesStore.nativeStoreWithFixedCapacity(4), 0, 4); value.setValue(1); final String expected = "test"; map.put(value, expected); final CharSequence actual = map.get(value); assertEquals(expected, actual.toString()); // this will fail map.toString(); } }
Example #10
Source File: MDPOffHeapBuffer.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public MDPOffHeapBuffer(int capacity) { NativeBytesStore<Void> emptyStore = NativeBytesStore.nativeStoreWithFixedCapacity(SbeConstants.MDP_PACKET_MAX_SIZE); emptyStore.writeUnsignedInt(MESSAGE_SEQ_NUM_OFFSET, UNDEFINED_VALUE); emptyPacket.buffer().copyFrom(emptyStore); data = new MdpPacket[capacity]; for (int i = 0; i < capacity; i++) { MdpPacket mdpPacket = MdpPacket.allocate(); mdpPacket.buffer().copyFrom(emptyStore); data[i] = mdpPacket; } }
Example #11
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEasyBoxMessageDeterministic() { BytesStore message = NativeBytesStore .from("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " + "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " + "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."); EasyBox.KeyPair alice = EasyBox.KeyPair.deterministic(123); EasyBox.KeyPair bob = EasyBox.KeyPair.deterministic(456); EasyBox.Nonce nonce = EasyBox.Nonce.deterministic(789); String expected = "970DC924AFCBD44DD20FA514CD328575BD70B483E3C88FE4C20F1F744CE18A8E6D543C3CA3D033B36D9341F32A34A098797762503ECEB8" + "C5D24E0C290CA08F5B7A188D3E0E4AB55D767A31F89546171BDE69BC64AFF116DD07A196D9B5D41FF6F7D273B92705450213A2BDCBA3A7" + "808C96646E8F0410BF5D2BDC05C71E3A35737D3276400372C0FC53631B445B94F2AB3E4DF55B1BE3B1373BAE36E5A44F0E4B046FF2FCBA" + "E8C55E89FDDE6468B0F908176745BA6D1DA788EF08546CC2A675067A6C3A907C765D97EF1C2184B9B748F6081F7168C57BBFABADB0357E" + "892A71DCED7867E4D3225A96598FBA9E3771509493C85085DE5ED05A597A45B3B7EF0A3C3FC8A1062AD67C48407C7B7DC0522167FE8295" + "DA52A0D311CE995159728FB51F1D2DFEB738442A6FD7C8CA4C9FEB2ED0584D12C5359D0EA558CFC72545CBB821754959DA35F6839866E6" + "C04A400E0FE9D8689426E9F1EAE1D77F93026D7B9E19A56353F59EFF980090053C09FB7CCF7438366AD0B9E9DB77042C0491B540646D02" + "FE8BB5C3A310B126C932290DD4885915F379A475E52B4025ED495B59BAC92C5487827065B26732A52545E5FCF044DBB3D5F827CA6B7CDF" + "E28062EC726BA7A0B0C73C058EDC66485C69663481"; long msglen = message.readRemaining(); BytesStore cipherText = EasyBox.encrypt(message, nonce, bob.publicKey, alice.secretKey); assertTrue(expected.equals(DatatypeConverter.printHexBinary(cipherText.toByteArray()))); long cipherlen = cipherText.readRemaining(); assertTrue(msglen + 16 == cipherlen); // 16 = CRYPTO_BOX_MACBYTES BytesStore message2 = EasyBox.decrypt(cipherText, nonce, alice.publicKey, bob.secretKey); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #12
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEasyBoxMessageDeterministicShared() { BytesStore message = NativeBytesStore .from("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " + "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " + "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."); EasyBox.KeyPair alice = EasyBox.KeyPair.deterministic(123); EasyBox.KeyPair bob = EasyBox.KeyPair.deterministic(456); EasyBox.SharedKey sharedA = EasyBox.SharedKey.precalc(bob.publicKey, alice.secretKey); EasyBox.SharedKey sharedB = EasyBox.SharedKey.precalc(alice.publicKey, bob.secretKey); assertEquals(DatatypeConverter.printHexBinary(sharedA.store.toByteArray()), DatatypeConverter.printHexBinary(sharedB.store.toByteArray())); EasyBox.Nonce nonce = EasyBox.Nonce.deterministic(789); String expected = "970DC924AFCBD44DD20FA514CD328575BD70B483E3C88FE4C20F1F744CE18A8E6D543C3CA3D033B36D9341F32A34A098797762503ECEB8" + "C5D24E0C290CA08F5B7A188D3E0E4AB55D767A31F89546171BDE69BC64AFF116DD07A196D9B5D41FF6F7D273B92705450213A2BDCBA3A7" + "808C96646E8F0410BF5D2BDC05C71E3A35737D3276400372C0FC53631B445B94F2AB3E4DF55B1BE3B1373BAE36E5A44F0E4B046FF2FCBA" + "E8C55E89FDDE6468B0F908176745BA6D1DA788EF08546CC2A675067A6C3A907C765D97EF1C2184B9B748F6081F7168C57BBFABADB0357E" + "892A71DCED7867E4D3225A96598FBA9E3771509493C85085DE5ED05A597A45B3B7EF0A3C3FC8A1062AD67C48407C7B7DC0522167FE8295" + "DA52A0D311CE995159728FB51F1D2DFEB738442A6FD7C8CA4C9FEB2ED0584D12C5359D0EA558CFC72545CBB821754959DA35F6839866E6" + "C04A400E0FE9D8689426E9F1EAE1D77F93026D7B9E19A56353F59EFF980090053C09FB7CCF7438366AD0B9E9DB77042C0491B540646D02" + "FE8BB5C3A310B126C932290DD4885915F379A475E52B4025ED495B59BAC92C5487827065B26732A52545E5FCF044DBB3D5F827CA6B7CDF" + "E28062EC726BA7A0B0C73C058EDC66485C69663481"; long msglen = message.readRemaining(); BytesStore cipherText = EasyBox.encryptShared(message, nonce, sharedA); assertTrue(expected.equals(DatatypeConverter.printHexBinary(cipherText.toByteArray()))); long cipherlen = cipherText.readRemaining(); assertTrue(msglen + 16 == cipherlen); // 16 = CRYPTO_BOX_MACBYTES BytesStore message2 = EasyBox.decryptShared(cipherText, nonce, sharedB); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #13
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testDecryptFailsFlippedKeys() { BytesStore message = NativeBytesStore.from("Hello World"); EasyBox.KeyPair alice = EasyBox.KeyPair.generate(); EasyBox.KeyPair bob = EasyBox.KeyPair.generate(); EasyBox.Nonce nonce = EasyBox.Nonce.generate(); BytesStore cipherText = EasyBox.encrypt(message, nonce, bob.publicKey, alice.secretKey); // NB: this - intentionally - won't compile. Need to force with the "unsafe" interface // EasyBox.decrypt(cipherText, nonce, bob.secretKey, alice.publicKey); EasyBox.decrypt(null, cipherText, nonce.store, bob.secretKey.store, alice.publicKey.store); }
Example #14
Source File: SealedBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEncryptDecrypt() { SealedBox.KeyPair kp = SealedBox.KeyPair.generate(); BytesStore message = NativeBytesStore.from("Hello World"); long msglen = message.readRemaining(); BytesStore c = SealedBox.encrypt(null, message, kp.publicKey); long clen = c.readRemaining(); assertTrue(msglen + 48 == clen); // 48 = CRYPTO_BOX_SEALBYTES BytesStore message2 = SealedBox.decrypt(null, c, kp.publicKey, kp.secretKey); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #15
Source File: SealedBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEncryptDecrypt2() { SealedBox.KeyPair kp = SealedBox.KeyPair.generate(); BytesStore message = NativeBytesStore.from("Hello World"); BytesStore c = SealedBox.encrypt(message, kp.publicKey); BytesStore message2 = SealedBox.decrypt(c, kp.publicKey, kp.secretKey); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #16
Source File: SealedBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEncryptDecrypt3() { SealedBox.KeyPair kp = SealedBox.KeyPair.generate(); BytesStore message = NativeBytesStore.from("Hello World"); BytesStore c = SealedBox.encrypt(null, message, kp.publicKey.store); BytesStore message2 = SealedBox.decrypt(null, c, kp.publicKey.store, kp.secretKey.store); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #17
Source File: SealedBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testDecryptFailsFlippedKeys() { SealedBox.KeyPair kp = SealedBox.KeyPair.generate(); BytesStore message = NativeBytesStore.from("Hello World"); BytesStore c = SealedBox.encrypt(null, message, kp.publicKey); // NB: this - intentionally - won't compile. Need to force with the "unsafe" interface // SealedBox.decrypt(cipherText, kp.secretKey, kp.publicKey); SealedBox.decrypt(null, c, kp.secretKey.store, kp.publicKey.store); }
Example #18
Source File: EasyBoxTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testEasyBox2() { System.out.println("sodium.version= " + Sodium.SODIUM.sodium_version_string()); BytesStore message = NativeBytesStore.from("test"); EasyBox.KeyPair alice = EasyBox.KeyPair.generate(); EasyBox.KeyPair bob = EasyBox.KeyPair.generate(); EasyBox.Nonce nonce = EasyBox.Nonce.generate(); BytesStore cipherText = EasyBox.encrypt(message, nonce, bob.publicKey, alice.secretKey); BytesStore message2 = EasyBox.decrypt(cipherText, nonce, alice.publicKey, bob.secretKey); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #19
Source File: VanillaChronicleHash.java From Chronicle-Map with Apache License 2.0 | 5 votes |
/** * @see net.openhft.chronicle.bytes.MappedFile#acquireByteStore(long, MappedBytesStoreFactory) */ private NativeBytesStore map(long mapSize, long mappingOffsetInFile) throws IOException { mapSize = pageAlign(mapSize); long minFileSize = mappingOffsetInFile + mapSize; FileChannel fileChannel = raf.getChannel(); if (fileChannel.size() < minFileSize) { // In MappedFile#acquireByteStore(), this is wrapped with fileLock(), to avoid race // condition between processes. This map() method is called either when a new tier is // allocated (in this case concurrent access is mutually excluded by // globalMutableStateLock), or on map creation, when race condition should be excluded // by self-bootstrapping header spec raf.setLength(minFileSize); // RandomAccessFile#setLength() only calls ftruncate, // which will not preallocate space on XFS filesystem of Linux. // And writing that file will create a sparse file with a large number of extents. // This kind of fragmented file may hang the program and cause dmesg reports // "XFS: ... possible memory allocation deadlock size ... in kmem_alloc (mode:0x250)". // We can fix this by trying calling posix_fallocate to preallocate the space. if (OS.isLinux()) { PosixFallocate.fallocate(raf.getFD(), 0, minFileSize); } } long address = OS.map(fileChannel, READ_WRITE, mappingOffsetInFile, mapSize); resources.addMemoryResource(address, mapSize); return new NativeBytesStore(address, mapSize, null, false); }
Example #20
Source File: InMemoryLongColumn.java From Chronicle-TimeSeries with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void ensureCapacity(long capacity) { long cap = lookup.sizeFor(capacity); if (cap > bytes.realCapacity()) { long value = lookup.sizeFor(capacity); BytesStore bytes2 = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); bytes2.write(0, bytes); bytes.release(); bytes = bytes2; } }
Example #21
Source File: IncrementalRefreshPerfTest.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
private Set<Integer> generateTestPackets(final MdpPacket samplePckt, final int testPacketsNum) { this.testPackets = new ArrayList<>(testPacketsNum); final Map<Integer, Integer> rptSeqNums = new HashMap<>(); final NativeBytesStore<Void> store = NativeBytesStore.nativeStoreWithFixedCapacity(samplePckt.getPacketSize()); samplePckt.buffer().copyTo(store); for (int i = 1; i <= testPacketsNum; i++) { store.writeUnsignedInt(MESSAGE_SEQ_NUM_OFFSET, i); final Iterator<MdpMessage> mdpMessageIterator = samplePckt.iterator(); while (mdpMessageIterator.hasNext()) { final MdpMessage mdpMessage = mdpMessageIterator.next(); final MdpMessageType messageType = mdpHandlerBuilder.getMdpMessageTypes().getMessageType(mdpMessage.getSchemaId()); mdpMessage.setMessageType(messageType); if (mdpMessage.getGroup(MdConstants.NO_MD_ENTRIES, incrGroup)) { while (incrGroup.hashNext()) { incrGroup.next(); final int secId = incrGroup.getInt32(MdConstants.SECURITY_ID); if (!rptSeqNums.containsKey(secId)) { rptSeqNums.put(secId, 0); } final int incrRptSeqNum = rptSeqNums.get(secId) + 1; final SbeGroup sbeGroup = (SbeGroup) incrGroup; final SbeFieldType fieldType = sbeGroup.getSbeGroupType().getMetadataContainer().findField(RPT_SEQ_NUM); final int offset = ((SbeGroup)incrGroup).getAbsoluteEntryOffset() + fieldType.getFieldType().getOffset().intValue(); store.writeUnsignedInt(offset, incrRptSeqNum); rptSeqNums.put(secId, incrRptSeqNum); } } } final byte[] bytes = new byte[samplePckt.getPacketSize()]; store.copyTo(bytes); testPackets.add(bytes); } samplePckt.release(); return rptSeqNums.keySet(); }
Example #22
Source File: InMemoryLongColumn.java From Chronicle-TimeSeries with GNU Lesser General Public License v3.0 | 5 votes |
public InMemoryLongColumn(TimeSeries timeSeries, String name, BytesLongLookup lookup, long capacity) { super(timeSeries, name); this.lookup = lookup; long value = lookup.sizeFor(capacity); this.bytes = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); }
Example #23
Source File: SHA2Test.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testMultiPart512() { BytesStore message1 = NativeBytesStore.from("Message part1"); BytesStore message2 = NativeBytesStore.from("Message part2"); BytesStore message3 = NativeBytesStore.from("Message part3"); SHA2.MultiPartSHA512 multi = new SHA2.MultiPartSHA512(); multi.add(message1); multi.add(message2); multi.add(message3); BytesStore hash = multi.hash(); assertEquals("D03F370D9C234701370A0323AF9BB5D0E13AEB128C6C14C427DD25B1FFCFA7EB" + "B505665AD2C97D989A3F460715D3C688FE04B9FC8AAA3213051486930A3B3876", DatatypeConverter.printHexBinary(hash.toByteArray())); }
Example #24
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testKeyPairLongSeed() { BytesStore seed = NativeBytesStore.from("01234567890123456789012345678901"); Signature.KeyPair kp = Signature.KeyPair.deterministic(seed); assertEquals("7BC3079518ED11DA0336085BF6962920FF87FB3C4D630A9B58CB6153674F5DD6", DatatypeConverter.printHexBinary(kp.publicKey.store.toByteArray())); }
Example #25
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testSignVerify() { BytesStore message = NativeBytesStore.from("test message"); Signature.KeyPair keys = Signature.KeyPair.generate(); BytesStore signed = Signature.sign(null, message, keys.secretKey); BytesStore unsigned = Signature.verify(null, signed, keys.publicKey); assertTrue(Arrays.equals(message.toByteArray(), unsigned.toByteArray())); }
Example #26
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testSignVerify2() { BytesStore message = NativeBytesStore.from("test message"); Signature.KeyPair keys = Signature.KeyPair.generate(); BytesStore signed = Signature.sign(message, keys.secretKey); BytesStore unsigned = Signature.verify(signed, keys.publicKey); assertTrue(Arrays.equals(message.toByteArray(), unsigned.toByteArray())); }
Example #27
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testSignVerify3() { BytesStore message = NativeBytesStore.from("test message"); Signature.KeyPair keys = Signature.KeyPair.generate(); BytesStore signed = Signature.sign(null, message, keys.secretKey.store); BytesStore unsigned = Signature.verify(null, signed, keys.publicKey.store); assertTrue(Arrays.equals(message.toByteArray(), unsigned.toByteArray())); }
Example #28
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void testSignatureDeterministic() { BytesStore message = NativeBytesStore .from("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " + "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " + "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."); Signature.KeyPair keys = Signature.KeyPair.deterministic(123); String expected = "1F02DE4C6263043CD7F6071263FA22BA7330D4F6383F15E28C7020E2C9D4A46F5B896FCBC9020B43741BBF1830246F4B7BF" + "5425200DC5405F1A1DE8AF241640A4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374" + "657475722061646970697363696E6720656C69742C2073656420646F20656975736D6F642074656D706F7220696E6369646" + "964756E74207574206C61626F726520657420646F6C6F7265206D61676E6120616C697175612E20557420656E696D206164" + "206D696E696D2076656E69616D2C2071756973206E6F737472756420657865726369746174696F6E20756C6C616D636F206" + "C61626F726973206E69736920757420616C697175697020657820656120636F6D6D6F646F20636F6E7365717561742E2044" + "756973206175746520697275726520646F6C6F7220696E20726570726568656E646572697420696E20766F6C75707461746" + "52076656C697420657373652063696C6C756D20646F6C6F726520657520667567696174206E756C6C612070617269617475" + "722E204578636570746575722073696E74206F6363616563617420637570696461746174206E6F6E2070726F6964656E742" + "C2073756E7420696E2063756C706120717569206F666669636961206465736572756E74206D6F6C6C697420616E696D2069" + "6420657374206C61626F72756D2E"; long msglen = message.readRemaining(); BytesStore signed = Signature.sign(message, keys.secretKey); assertTrue(expected.equals(DatatypeConverter.printHexBinary(signed.toByteArray()))); long signedlen = signed.readRemaining(); assertTrue(msglen + 64 == signedlen); // 16 = CRYPTO_BOX_MACBYTES BytesStore message2 = Signature.verify(signed, keys.publicKey); assertTrue(Arrays.equals(message.toByteArray(), message2.toByteArray())); }
Example #29
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testVerifyFailsFlippedKeys() { BytesStore message = NativeBytesStore.from("Hello World"); Signature.KeyPair keys = Signature.KeyPair.generate(); BytesStore signed = Signature.sign(message, keys.secretKey); // NB: this - intentionally - won't compile. Need to force with the "unsafe" interface // Signature.verify(signed, keys.publicKey); Signature.verify(null, signed, keys.secretKey.store); }
Example #30
Source File: SignatureTest.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
@Test public void extractTest2() { BytesStore seed = NativeBytesStore.from("01234567890123456789012345678901"); Signature.KeyPair keys = Signature.KeyPair.deterministic(seed); BytesStore seed2 = keys.secretKey.extractSeed(); assertEquals("3031323334353637383930313233343536373839303132333435363738393031", DatatypeConverter.printHexBinary(seed2.toByteArray())); BytesStore pk = keys.secretKey.extractPublicKey(); assertEquals("7BC3079518ED11DA0336085BF6962920FF87FB3C4D630A9B58CB6153674F5DD6", DatatypeConverter.printHexBinary(pk.toByteArray())); assertTrue(Arrays.equals(keys.publicKey.store.toByteArray(), pk.toByteArray())); }