github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/consensus/poet/sgx/tests/test_sgx/utils.py (about)

     1  # Copyright 2017 Intel Corporation
     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  # ------------------------------------------------------------------------------
    15  
    16  import random
    17  import string
    18  import hashlib
    19  
    20  from sawtooth_signing import create_context
    21  
    22  
    23  CONTEXT = create_context('secp256k1')
    24  
    25  
    26  def random_name(length=16):
    27      return ''.join(
    28          random.SystemRandom().choice(string.ascii_uppercase + string.digits)
    29          for _ in range(length))
    30  
    31  
    32  def create_random_private_key():
    33      return CONTEXT.new_random_private_key()
    34  
    35  
    36  def create_random_public_key():
    37      return CONTEXT.get_public_key(create_random_private_key())
    38  
    39  
    40  def create_random_public_key_hash():
    41      public_key_bytes = create_random_public_key().as_hex().encode()
    42      return hashlib.sha256(public_key_bytes).hexdigest()