<s> """<STR_LIT>""" <EOL> import array <EOL> import codecs <EOL> from oslo_log import log as logging <EOL> from oslo_utils import uuidutils <EOL> from nova import exception <EOL> from nova . i18n import _LW <EOL> from nova . keymgr import key <EOL> from nova . keymgr import key_mgr <EOL> from nova import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> decode_hex = codecs . getdecoder ( "<STR_LIT>" ) <EOL> class MockKeyManager ( key_mgr . KeyManager ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> LOG . warning ( _LW ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . keys = { } <EOL> def _generate_hex_key ( self , ** kwargs ) : <EOL> key_length = kwargs . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> hex_encoded = utils . generate_password ( length = key_length // <NUM_LIT:4> , <EOL> symbolgroups = '<STR_LIT>' ) <EOL> return hex_encoded <EOL> def _generate_key ( self , ** kwargs ) : <EOL> _hex = self . _generate_hex_key ( ** kwargs ) <EOL> return key . SymmetricKey ( '<STR_LIT>' , <EOL> array . array ( '<STR_LIT:B>' , decode_hex ( _hex ) [ <NUM_LIT:0> ] ) . tolist ( ) ) <EOL> def create_key ( self , ctxt , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ctxt is None : <EOL> raise exception . Forbidden ( ) <EOL> key = self . _generate_key ( ** kwargs ) <EOL> return self . store_key ( ctxt , key ) <EOL> def _generate_key_id ( self ) : <EOL> key_id = uuidutils . generate_uuid ( ) <EOL> while key_id in self . keys : <EOL> key_id = uuidutils . generate_uuid ( ) <EOL> return key_id <EOL> def store_key ( self , ctxt , key , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ctxt is None : <EOL> raise exception . Forbidden ( ) <EOL> key_id = self . _generate_key_id ( ) <EOL> self . keys [ key_id ] = key <EOL> return key_id <EOL> def copy_key ( self , ctxt , key_id , ** kwargs ) : <EOL> if ctxt is None : <EOL> raise exception . Forbidden ( ) <EOL> copied_key_id = self . _generate_key_id ( ) <EOL> self . keys [ copied_key_id ] = self . keys [ key_id ] <EOL> return copied_key_id <EOL> def get_key ( self , ctxt , key_id , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ctxt is None : <EOL> raise exception . Forbidden ( ) <EOL> return self . keys [ key_id ] <EOL> def delete_key ( self , ctxt , key_id , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ctxt is None : <EOL> raise exception . Forbidden ( ) <EOL> del self . keys [ key_id ] </s>
