Function ssb_verify_signatures::par_verify_message_values[][src]

pub fn par_verify_message_values<T: AsRef<[u8]>>(
    msgs: &[T],
    chunk_size: Option<usize>
) -> Result<(), Error> where
    [T]: ParallelSlice<T>,
    T: Sync

Checks signatures of a slice of message values in parallel.

It expects the messages to be the JSON encoded message value of shape: { previous: "", author: "", sequence: ..., timestamp: ..., content: {}, signature: "" }

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_value method in this crate once this method returns an error.

Example

use ssb_verify_signatures::par_verify_message_values;
let valid_message_value = r##"{
  "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"
}"##.as_bytes();
 let values = [valid_message_value, valid_message_value, valid_message_value];
 let result = par_verify_message_values(&values, None);
 assert!(result.is_ok());