Function ssb_verify_signatures::par_verify_messages [−][src]
pub fn par_verify_messages<T: AsRef<[u8]>>(
msgs: &[T],
chunk_size: Option<usize>
) -> Result<(), Error> where
[T]: ParallelSlice<T>,
T: Sync,
Checks signatures of a slice of messages in parallel.
It expects the messages to be the JSON encoded message of shape: {key: "", value: {...}}
Uses ed25519_dalek
’s batch verify method to take advantage of processors with SIMD
instructions, and process them in parallel using rayon
.
You may pass an Option<usize>
for chunk_size
or, if None
, a default of CHUNK_SIZE
is used.
Returns Ok(())
if all messages are ok, and an Err(InvalidSignature)
if any signature fails.
Unfortunately ed25519_dalek::verify_batch
does not return which message failed to verify,
If you need to work out which message failed, you might have to find
it using the verify_message method in this crate once this method returns an error.
Example
use ssb_verify_signatures::par_verify_messages; let valid_message = r##"{ "key": "%kmXb3MXtBJaNugcEL/Q7G40DgcAkMNTj3yhmxKHjfCM=.sha256", "value": { "previous": "%IIjwbJbV3WBE/SBLnXEv5XM3Pr+PnMkrAJ8F+7TsUVQ=.sha256", "author": "@U5GvOKP/YUza9k53DSXxT0mk3PIrnyAmessvNfZl5E0=.ed25519", "sequence": 8, "timestamp": 1470187438539, "hash": "sha256", "content": { "type": "contact", "contact": "@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519", "following": true, "blocking": false }, "signature": "PkZ34BRVSmGG51vMXo4GvaoS/2NBc0lzdFoVv4wkI8E8zXv4QYyE5o2mPACKOcrhrLJpymLzqpoE70q78INuBg==.sig.ed25519" }, "timestamp": 1571140551543 }"##.as_bytes(); let messages = [valid_message, valid_message, valid_message]; let result = par_verify_messages(&messages, None); assert!(result.is_ok());