[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SNACC::SnaccException m_errorCode clashes and literal constants



I am trying to write a function that, given a caught
SNACC::SnaccException object, turns the m_errorCode field into a
string.  As it stands, my function is as shown below.

There are 2 problems:

1. Parts of the sm_free3 code call SME_THROW with literal integer
constants rather than #defined values.  This was also the case in SFL
2.1, but I was hoping it would have been remedied in SFL 2.3.  Instead
more code has been added that follows the same practice.

2. Both SNACC and sm_free3 define 6000 as the base for their error
codes, and there are 9 clashes.  I believe that a caught SnaccException
could potentially contain an error code from either group, so I cannot
determine which string is appropriate.  I think this problem may have
been caused by the merging of exception classes.

Please let me know if my function has omitted any codes that may be
returned, and confirm that these issues will be resolved in the next SFL
release.

-- 
John Stark
Tel: +44 1223 566732
Mobile: +44 7968 110628
E-mail: jas@xxxxxxxxxxxx
Web: http://www.metanate.com


static const char *error_string(const unsigned sfl_error_code)
{
  switch (sfl_error_code)
  {
    // No error.
    case SM_NO_ERROR:
      return "Success";

    // smp/sm_apicCert.h
    case CMLASN_MEMORY_ERROR:
      return "Memory error";
    case CMLASN_INVALID_PARAMETER:
      return "Invalid parameter";
    case CMLASN_NULL_POINTER:
      return "Null pointer";
    case CMLASN_NOT_IMPLEMENTED:
      return "Not implemented";
    case CMLASN_DECODE_ERROR:
      return "Decode error";
    case CMLASN_SNACC_ERROR:
      return "SNACC error";
    case CMLASN_FILE_IO_ERROR:
      return "File I/O error";
    case CMLASN_INVALID_DN:
      return "Invalid DN";
    case CMLASN_UNKNOWN_ERROR:
      return "Unknown error";

    // smp/sm_apicCert.h
    case SM_MEMORY_ERROR:
      return "Memory error";
    case SM_FILEIO_ERROR:
      return "File I/O error";
    case SM_NO_FILENAME:
      return "No filename";
    case SM_MISSING_PARAM:
      return "Missing parameter";
    case SM_MAB_ERROR:
      return "MAB error";
    case SM_NO_INSTANCES:
      return "No instances";
    case SM_NO_SUPPORTING_INSTANCE:
      return "No supporting instance";
    case SM_ENCRYPTION_UNPREPARED:
      return "Encryption unprepared";
    case SM_INVALID_INDEX:
      return "Invalid instance";
    case SM_ASN1_DECODE_ERROR:
      return "ASN.1 decode error";
    case SM_INVL_PREPROC_TYPE:
      return "Invalid preprocess type";
    case SM_ORIGMSG_NOT_SIGNEDDATA:
      return "Original message not SignedData";
    case SM_NO_MATCHING_SIGNATURE:
      return "No matching signature";
    case SM_VALRECERR_MSG_SIG_DIGEST:
      return "Message signature digest mismatch";
    case SM_VALRECERR_MSG_DIGEST:
      return "Message digest mismatch";
    case SM_DIGEST_MISMATCH:
      return "Digest mismatch";
    case SM_RECREQ_ERROR:
      return "Receipt request error";
    case SM_NO_RECEIPTS_FROM:
      return "No receipts from";
    case SM_UNKNOWN_ATTRIBUTE:
      return "Unknown attribute";
    case SM_DUPLICATE_ATTRIBS:
      return "Duplicate attributes";
    case SM_NOT_FOUND:
      return "Not found";
    case SM_UNKNOWN_CID:
      return "Unknown CHOICE ID";
    case SM_NO_SIGNER_IDENTIFIER:
      return "No signer identifier";
    case SM_INVALID_CRL:
      return "Invalid CRL";
    case SM_NO_CRL_SET:
      return "No CRL set";
    case SM_CRL_DEC_ERROR:
      return "Decode error";
    case SM_INVALID_OID_STRING:
    // AES errors
    case SM_AES_ENCRYPT_ERROR:
      return "Encrypt error";
    case SM_AES_DECRYPT_ERROR:
      return "Decrypt error";
    case SM_AES_MISALIGNED_DATA:
      return "Misaligned data";
    case SM_AES_KEYINST_ERROR:
      return "Key instance error";
    case SM_AES_PAD_ERROR:
      return "Pad error";
    case SM_AES_CIPHER_ERROR:
      return "Cipher error";
    // ASN.1 ERROR CONSTANTS 2000-2999
    case SM_ENV_DATA_DEC_ERROR:
      return "Data decode error";

    // Literal numeric error codes thrown in sm_free3 source.
    case 22:
      return "Unsupported algorithm";
    case 25:
      return "Unsupported key wrap algorithm";
    case 26:
      return "Missing DSA parameters";
    case 27:
      return "PBE key generation error";
    case 29:
      return "PKCS#12 decode error";
    case 30:
      return "No certificates in PKCS#12 file";
    case 33:
      return "ASN.1 encode failure";
    case 44:
      return "PKCS#12 error";
    case 99:
      return "Invalid algorithm";

    // SM_FREE errors 6000-6999
    // smp/sm_free3.h
    case SM_FREE_MISSING_PARAM:
      return "Missing parameter";
    case SM_FREE_PARAM_DEC_ERROR:
      return "Parameters ASN.1 decoding error";
    case SM_FREE_UNSUPPORTED_ALG:
      return "Unsupported algorithm";
    case SM_FREE_VERIFY_FAILED:
      return "Signature verification failed";
    case SM_FREE_NO_DIGEST_ALG:
      return "No preferred digest algorithm set";
    case SM_FREE_MAB_NO_ISSUER:
      return "Can't find issuer certificate in address book";
    case SM_FREE_ISSUER_NOT_DSA:
      return "Issuer certificate in address book is not DSA";
    case SM_FREE_PUT_Y_ERROR:
      return "Attempt to load public key failed";
    case SM_FREE_DECRYPT_PAD_ERROR:
      return "Pad values in final block of ciphertext incorrect";
    case SM_FREE_DECODE_ERROR:
      return "ASN.1 decoding error";

    // SNACC errors: esnacc/c++/snaccexcept.h.
#if	0
    // These clash with the sm_free3 error codes!
    case MEMORY_ERROR:		return "Memory allocation failed";
    case BOUNDS_ERROR:		return "Length of object is invalid";
    case INVALID_TAG:		return "Invalid ASN.1 Tag for object";
    case INVALID_ANY:		return "Invalid ANY";
    case DECODE_ERROR:		return "Decoded past end of data";
    case RESTRICTED_TYPE_ERROR:	return "Restricted type check failed";
    case INTEGER_ERROR:		return "Integer related errors";
    case PARAMETER_ERROR:	return "Invalid parameter";
    case OID_ERROR:		return "OID related error";
#endif
    case FILE_IO_ERROR:		return "File error";
    case BUFFER_ERROR:		return "Buffer error";
    case ENCODE_ERROR:		return "General encode error";
    default:
      return "Unknown SFL error";
  }
}