code: def input_validate_nonce(nonce, name='nonce', pad = False):
      
      if type(nonce) is not str:
          raise pyhsm.exception.YHSM_WrongInputType( \
              name, str, type(nonce))
      if len(nonce) > pyhsm.defines.YSM_AEAD_NONCE_SIZE:
          raise pyhsm.exception.YHSM_InputTooLong(
              name, pyhsm.defines.YSM_AEAD_NONCE_SIZE, len(nonce))
      if pad:
          return nonce.ljust(pyhsm.defines.YSM_AEAD_NONCE_SIZE, chr(0x0))
      else:
          return nonce
docs: Input validation for nonces.