def init_pubkey(hexpk, fname=None): """Create a pubkey object from a hex formatted string. Save to file fname if specified. """ pk = public.PublicKey(binascii.unhexlify(hexpk)) if fname: pk.save(fname) return pk
def init_pubkey(hexpk, fname=None): """Create a pubkey object from a hex formatted string. Save to file fname if specified. """ try: bin_pk = binascii.unhexlify(hexpk) except TypeError: raise NaclError("Invalid hex") if not len(bin_pk) == 32: raise NaclError("Public key must be 32 bytes") pk = public.PublicKey(binascii.unhexlify(hexpk)) if fname: pk.save(fname) return pk