pub struct Hash {
pub input: InputPort<Bytes>,
pub output: OutputPort<Bytes>,
pub hash: OutputPort<Bytes>,
pub algorithm: HashAlgorithm,
/* private fields */
}Expand description
Computes the cryptographic hash of a byte stream, while optionally passing it through.
§Block Diagram
block-beta
columns 7
Source space:2 Hash space:2 Sink
space:7
space:7
space:3 Result space:3
Source-- "input" -->Hash
Hash-- "output" -->Sink
Hash-- "hash" -->Result
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Hash block
class Source hidden
class Sink hidden
class Result hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant BlockA as Another block
participant Hash.input as Hash.input port
participant Hash as Hash block
participant Hash.output as Hash.output port
participant BlockB as Another block
participant Hash.hash as Hash.hash port
participant BlockC as Another block
BlockA-->>Hash: Connect
Hash-->>BlockB: Connect
loop Hash process
BlockA->>Hash: Message (Bytes)
Hash->>Hash: Update state
Hash->>BlockB: Message (Bytes)
end
BlockA-->>Hash: Disconnect
Hash-->>Hash.input: Close
Hash-->>Hash.output: Close
Hash-->>BlockB: Disconnect
Hash-->>BlockC: Connect
Hash->>BlockC: Hash
Hash-->>Hash.hash: Close
Hash-->>BlockC: Disconnect
%% TODO
§Examples
§Using the block in a system
System::build(|s| {
let stdin = s.read_stdin();
let hasher = s.hash_blake3();
let hex_encoder = s.encode_hex();
let stdout = s.write_stdout();
s.connect(&stdin.output, &hasher.input);
s.connect(&hasher.hash, &hex_encoder.input);
s.connect(&hex_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute Hash algorithm=blake3Fields§
§input: InputPort<Bytes>The input byte stream.
output: OutputPort<Bytes>The (optional) output target for the stream being passed through.
hash: OutputPort<Bytes>The output port for the computed hash.
algorithm: HashAlgorithmA configuration parameter for which algorithm to use.
Implementations§
Source§impl Hash
impl Hash
pub fn new( input: InputPort<Bytes>, output: OutputPort<Bytes>, hash: OutputPort<Bytes>, ) -> Self
pub fn with_params( input: InputPort<Bytes>, output: OutputPort<Bytes>, hash: OutputPort<Bytes>, algorithm: Option<HashAlgorithm>, ) -> Self
pub fn with_system(system: &System, algorithm: Option<HashAlgorithm>) -> Self
Trait Implementations§
Source§impl Block for Hash
impl Block for Hash
Source§fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
Executes this block’s computation.
Source§fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
Prepares this block for execution. Read more
Source§impl BlockDescriptor for Hash
impl BlockDescriptor for Hash
Source§fn inputs(&self) -> Vec<PortDescriptor>
fn inputs(&self) -> Vec<PortDescriptor>
A description of this block’s input ports.
Source§fn outputs(&self) -> Vec<PortDescriptor>
fn outputs(&self) -> Vec<PortDescriptor>
A description of this block’s output ports.
Source§fn parameters(&self) -> Vec<ParameterDescriptor>
fn parameters(&self) -> Vec<ParameterDescriptor>
A description of this block’s parameters.
Source§fn ports(&self) -> Vec<PortDescriptor>
fn ports(&self) -> Vec<PortDescriptor>
A description of this block’s I/O ports.
Source§impl MaybeLabeled for Hash
impl MaybeLabeled for Hash
Source§impl MaybeNamed for Hash
impl MaybeNamed for Hash
Source§impl StdioSystem for Hash
impl StdioSystem for Hash
fn build_system(config: StdioConfig) -> Result<System, StdioError>
Auto Trait Implementations§
impl Freeze for Hash
impl !RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl !UnwindSafe for Hash
Blanket Implementations§
Source§impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
fn as_block_descriptor(&self) -> &dyn BlockDescriptor
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more