def validate(decline, online, default): """ Returns true if the decline, online and default command line parameters are well formated and usable and False if this is not the case. Examples ============== >>> validate("0000000000","0000000000","0000000000") True >>> validate("0000000000","00","0000000000") False >>> validate("xxxxxxxxxx","0000000000","zzzzzzzzzz") False >>> validate("0011223344","5566778899","aaBbccDdEE") True >>> validate("0011223344","5566778899","aaBbffDdEE") True >>> validate("q011223344","5566778899","aaBbffDdEE") False """ # All xIAC must have the same length. l = [decline, online, default] lengths_ok = len(set([len(i) for i in l])) == 1 # ALL xIAC must be HEX values. are_hex = util.is_hex(decline + online + default) return lengths_ok and are_hex
def trust_key_cmd(parsed_args, buf): nickname = parsed_args[1] hexed_key = parsed_args[2] # Check for illegal nickname chars if not nickname.isalnum(): util.control_msg("Invalid nickname: %s" % nickname) raise flute.FluteCommandError if len(hexed_key) != 64 or not util.is_hex(hexed_key): util.control_msg("Invalid key value: %s" % hexed_key) raise flute.FluteCommandError account = accounts.get_my_account() account.trust_key(nickname, hexed_key)
def validate(tlv): """ Validate a ber-tlv encoded string on the basis that it's made up only of HEX symbol and that it is made up of bytes (even length). Example ======= >>> validate('9f110101') True >>> validate('840E315041592E5359532E4444463031') True >>> validate('') False >>> validate('0x9f110101') False """ return (len(tlv) % 2 == 0) and util.is_hex(tlv)
def validate(aip): """ Returns True is AIP is valid on the basis of having a lenght of 2 bytes hex coded values. Example ======= >>> validate('3900') True >>> validate('1980') True >>> validate('198g') False >>> validate('090') False >>> validate('00090') False """ return len(aip) == 4 and util.is_hex(aip)
def validate(cvm): """ Returns True if the CVM list is valid on the basis of having the right amount of bytes for amounts x and y + bytes for a t least 1 cmv list. Each subsequent CVM must be 2 bytes long. CVM Example ======= >>> validate('00000000000000004103') True >>> validate('000000000000010141035e03') True >>> validate('0000004103') False >>> validate('00004103') False >>> validate('00000000004103') False >>> validate('') False """ return len(cvm) >= 12 and (len(cvm) - 12) % 4 == 0 and util.is_hex(cvm)