ink_codegen/generator/blake2b.rs
1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::GenerateCode;
16use derive_more::From;
17use ir::HexLiteral;
18use proc_macro2::TokenStream as TokenStream2;
19use quote::quote_spanned;
20
21/// Generates code for the `selector_id!` macro.
22#[derive(From)]
23pub struct Blake2x256<'a> {
24 /// The `blake2x256!` macro input.
25 macro_input: &'a ir::Blake2x256Macro,
26}
27
28impl GenerateCode for Blake2x256<'_> {
29 /// Generates `selector_id!` macro code.
30 fn generate_code(&self) -> TokenStream2 {
31 let span = self.macro_input.input().span();
32 let hash_bytes = self
33 .macro_input
34 .hash()
35 .map(|byte| byte.hex_padded_suffixed());
36 quote_spanned!(span=> [ #( #hash_bytes ),* ] )
37 }
38}