old_contents: # -*- coding: utf-8 -*-
  
  # Import nacl libs
  import libnacl
  import libnacl.encode
  import libnacl.public
  import libnacl.sign
  import libnacl.dual
  
  # Import python libs
  import time
  import binascii
  
  
  def load_key(path, serial='json'):
      '''
      Read in a key from a file and return the applicable key object based on
      the contents of the file
      '''
      with open(path, 'rb') as fp_:
          packaged = fp_.read()
      if serial == 'msgpack':
          import msgpack
          key_data = msgpack.loads(packaged)
      elif serial == 'json':
          import json
          key_data = json.loads(packaged.decode(encoding='UTF-8'))
      if 'priv' and 'sign' in key_data:
          return libnacl.dual.DualSecret(
                  libnacl.encode.hex_decode(key_data['priv']),
                  libnacl.encode.hex_decode(key_data['sign']))
      elif 'priv' in key_data:
          return libnacl.public.SecretKey(
                  libnacl.encode.hex_decode(key_data['priv']))
      elif 'sign' in key_data:
          return libnacl.sign.Signer(
                  libnacl.encode.hex_decode(key_data['sign']))
      elif 'pub' in key_data:
          return libnacl.public.PublicKey(
                  libnacl.encode.hex_decode(key_data['pub']))
      elif 'verify' in key_data:
          return libnacl.sign.Verifier(key_data['verify'])
      raise ValueError('Found no key data')
  
  
  def salsa_key():
      '''
      Generates a salsa2020 key
      '''
      return libnacl.randombytes(libnacl.crypto_secretbox_KEYBYTES)
  
  
  def time_nonce(size=24):
      '''
      Generates a safe nonce
  
      The nonce generated here is done by grabbing the 20 digit microsecond
      timestamp and appending 4 random chars
      '''
      size = max(int(size), 16)
      front = '{0:0x}'.format(int(time.time() * 1000000))
      extra = size - len(front)
      back = binascii.hexlify(libnacl.randombytes(extra // 2 + extra % 2))
      nonce = ((front + back.decode(encoding='UTF-8'))[:size])
      return nonce.encode(encoding='UTF-8')
  
new_contents: # -*- coding: utf-8 -*-
  
  # Import nacl libs
  import libnacl
  import libnacl.encode
  import libnacl.public
  import libnacl.sign
  import libnacl.dual
  
  
  def load_key(path, serial='json'):
      '''
      Read in a key from a file and return the applicable key object based on
      the contents of the file
      '''
      with open(path, 'rb') as fp_:
          packaged = fp_.read()
      if serial == 'msgpack':
          import msgpack
          key_data = msgpack.loads(packaged)
      elif serial == 'json':
          import json
          key_data = json.loads(packaged.decode(encoding='UTF-8'))
      if 'priv' and 'sign' in key_data:
          return libnacl.dual.DualSecret(
                  libnacl.encode.hex_decode(key_data['priv']),
                  libnacl.encode.hex_decode(key_data['sign']))
      elif 'priv' in key_data:
          return libnacl.public.SecretKey(
                  libnacl.encode.hex_decode(key_data['priv']))
      elif 'sign' in key_data:
          return libnacl.sign.Signer(
                  libnacl.encode.hex_decode(key_data['sign']))
      elif 'pub' in key_data:
          return libnacl.public.PublicKey(
                  libnacl.encode.hex_decode(key_data['pub']))
      elif 'verify' in key_data:
          return libnacl.sign.Verifier(key_data['verify'])
      raise ValueError('Found no key data')
  
  
  def salsa_key():
      '''
      Generates a salsa2020 key
      '''
      return libnacl.randombytes(libnacl.crypto_secretbox_KEYBYTES)
  
  
  def rand_nonce():
      '''
      Generates and returns a random bytestring of the size defined in libsodium
      as crypto_box_NONCEBYTES
      '''
      return libnacl.randombytes(libnacl.crypto_box_NONCEBYTES)
  
subject: remove time_nonce and add rand_nonce