<s> from mixbox import entities <EOL> from mixbox import fields <EOL> from mixbox . vendor import six <EOL> from mixbox . vendor . six import u <EOL> import cybox . bindings . cybox_common as common_binding <EOL> from cybox . common import vocabs , HexBinary , String , VocabString <EOL> from cybox . common . vocabs import HashName <EOL> def _set_hash_type ( entity , value ) : <EOL> """<STR_LIT>""" <EOL> if entity . type_ : <EOL> return <EOL> if not value : <EOL> return <EOL> hashlen = len ( value . value ) <EOL> if hashlen == <NUM_LIT:32> : <EOL> entity . type_ = Hash . TYPE_MD5 <EOL> elif hashlen == <NUM_LIT> : <EOL> entity . type_ = Hash . TYPE_SHA1 <EOL> elif hashlen == <NUM_LIT> : <EOL> entity . type_ = Hash . TYPE_SHA224 <EOL> elif hashlen == <NUM_LIT:64> : <EOL> entity . type_ = Hash . TYPE_SHA256 <EOL> elif hashlen == <NUM_LIT> : <EOL> entity . type_ = Hash . TYPE_SHA384 <EOL> elif hashlen == <NUM_LIT> : <EOL> entity . type_ = Hash . TYPE_SHA512 <EOL> else : <EOL> entity . type_ = Hash . TYPE_OTHER <EOL> class Hash ( entities . Entity ) : <EOL> _binding = common_binding <EOL> _binding_class = common_binding . HashType <EOL> _namespace = '<STR_LIT>' <EOL> type_ = vocabs . VocabField ( "<STR_LIT>" , HashName ) <EOL> simple_hash_value = fields . TypedField ( "<STR_LIT>" , HexBinary , <EOL> postset_hook = _set_hash_type ) <EOL> fuzzy_hash_value = fields . TypedField ( "<STR_LIT>" , String ) <EOL> TYPE_MD5 = u ( "<STR_LIT>" ) <EOL> TYPE_MD6 = u ( "<STR_LIT>" ) <EOL> TYPE_SHA1 = u ( "<STR_LIT>" ) <EOL> TYPE_SHA224 = u ( "<STR_LIT>" ) <EOL> TYPE_SHA256 = u ( "<STR_LIT>" ) <EOL> TYPE_SHA384 = u ( "<STR_LIT>" ) <EOL> TYPE_SHA512 = u ( "<STR_LIT>" ) <EOL> TYPE_SSDEEP = u ( "<STR_LIT>" ) <EOL> TYPE_OTHER = VocabString ( u ( "<STR_LIT>" ) ) <EOL> def __init__ ( self , hash_value = None , type_ = None , exact = False ) : <EOL> """<STR_LIT>""" <EOL> super ( Hash , self ) . __init__ ( ) <EOL> self . type_ = type_ <EOL> self . simple_hash_value = hash_value <EOL> if exact : <EOL> if self . simple_hash_value : <EOL> self . simple_hash_value . condition = "<STR_LIT>" <EOL> if self . type_ : <EOL> self . type_ . condition = "<STR_LIT>" <EOL> def __str__ ( self ) : <EOL> return str ( self . simple_hash_value ) <EOL> class HashList ( entities . EntityList ) : <EOL> _binding = common_binding <EOL> _binding_class = common_binding . HashListType <EOL> _binding_var = "<STR_LIT>" <EOL> _contained_type = Hash <EOL> _namespace = '<STR_LIT>' <EOL> def _fix_value ( self , value ) : <EOL> if isinstance ( value , six . string_types ) : <EOL> return Hash ( value ) <EOL> @ property <EOL> def md5 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_MD5 ) <EOL> @ md5 . setter <EOL> def md5 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_MD5 , value ) <EOL> @ property <EOL> def sha1 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_SHA1 ) <EOL> @ sha1 . setter <EOL> def sha1 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_SHA1 , value ) <EOL> @ property <EOL> def sha224 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_SHA224 ) <EOL> @ sha224 . setter <EOL> def sha224 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_SHA224 , value ) <EOL> @ property <EOL> def sha256 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_SHA256 ) <EOL> @ sha256 . setter <EOL> def sha256 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_SHA256 , value ) <EOL> @ property <EOL> def sha384 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_SHA384 ) <EOL> @ sha384 . setter <EOL> def sha384 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_SHA384 , value ) <EOL> @ property <EOL> def sha512 ( self ) : <EOL> return self . _get_hash_value ( Hash . TYPE_SHA512 ) <EOL> @ sha512 . setter <EOL> def sha512 ( self , value ) : <EOL> self . _set_hash ( Hash . TYPE_SHA512 , value ) <EOL> def _hash_lookup ( self , type_ ) : <EOL> for h in self : <EOL> if h . type_ == type_ : <EOL> return h . simple_hash_value <EOL> return None <EOL> def _set_hash ( self , type_ , value ) : <EOL> h = self . _hash_lookup ( type_ ) <EOL> if h : <EOL> h . simple_hash_value = value <EOL> else : <EOL> self . append ( Hash ( value , type_ ) ) <EOL> def _get_hash_value ( self , type_ ) : <EOL> """<STR_LIT>""" <EOL> h = self . _hash_lookup ( type_ ) <EOL> if h : <EOL> return h . value <EOL> return None </s>
