github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/perf/intkey_workload/src/intkey_addresser.rs (about) 1 /* 2 * Copyright 2018 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 use crypto::digest::Digest; 19 use crypto::sha2::Sha512; 20 21 pub struct IntKeyAddresser { 22 namespace: String, 23 pub family_name: String, 24 pub version: String, 25 } 26 27 impl IntKeyAddresser { 28 pub fn new() -> IntKeyAddresser { 29 let mut hasher = Sha512::new(); 30 hasher.input_str("intkey"); 31 32 IntKeyAddresser { 33 namespace: hasher.result_str()[..6].to_string(), 34 family_name: "intkey".to_string(), 35 version: "1.0".to_string(), 36 } 37 } 38 39 pub fn make_address(&self, name: &str) -> String { 40 let prefix = self.namespace.clone(); 41 let mut hasher = Sha512::new(); 42 hasher.input(name.as_bytes()); 43 (prefix + &hasher.result_str()[64..]).to_string() 44 } 45 }