📄 ospasn1primitives.c
字号:
{ for (i = 0 ; (i < intBuf->DigitCount) && (smallValue <= 0x7FFFFF) ; i++) { smallValue *= 256; smallValue += intBuf->Digits[i]; } if (i == intBuf->DigitCount) { OSPM_MALLOC(intBuf->SmallValue, int, sizeof(int)); if (intBuf->SmallValue == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_UNABLE_TO_ALLOCATE_SPACE; OSPM_DBGERRORLOG(errorcode, "Unable to allocate integer smallvalue"); } else { *(intBuf->SmallValue) = smallValue; } } } } if (errorcode == OSPC_ERR_NO_ERROR) { *ospvInteger = intBuf; } else { OSPPASN1IntegerDelete(&intBuf); } return errorcode;}int OSPPASN1IntegerEncode( OSPTASN1ELEMENTINFO *ospvElementInfo){ OSPTASN1ELEMENTINFO *eInfo; int errorcode = OSPC_ERR_NO_ERROR; OSPTASN1INTEGER *intBuf; errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; intBuf = (OSPTASN1INTEGER *)eInfo->ContentValue; eInfo->Content = intBuf->Digits; eInfo->ContentLength = intBuf->DigitCount; } return errorcode;}/***************************************** OBJECT IDENTIFIER ROUTINES *****************************************/int OSPPASN1ObjectIdentifierDecode( void **osvpContentValue, unsigned char *ospvEncodedData, unsigned int ospvEncodedDataLength)OSPTASN1ELEMENTINFO *ospvElementInfo){ OSPTASN1ELEMENTINFO *eInfo; int errorcode = OSPC_ERR_NO_ERROR; if (ospvContentValue == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_INVALID_PARAMETER; OSPM_DBGERRORLOG(errorcode, "Null pointer supplied for return value"); } else if ((ospvEncodedData != OSPC_OSNULL) && (ospvEncodedDataLength == 0)) { errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; errorcode = OSPPASN1BufferCreate(eInfo->Content, eInfo->ContentLength, (OSPTASN1BUFFER **)&(eInfo->ContentValue)); } return errorcode; } /***************************************** PRINTABLE STRING ROUTINES *****************************************/ int OSPPASN1PrintableStringEncode( OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo; OSPTASN1BUFFER *buffer; int errorcode = OSPC_ERR_NO_ERROR; errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; buffer = (OSPTASN1BUFFER *)eInfo->ContentValue; eInfo->Content = buffer->Buffer; eInfo->ContentLength = buffer->BufferLength; } return errorcode; } int OSPPASN1PrintableStringDecode( void **osvpContentValue, unsigned char *ospvEncodedData, unsigned int ospvEncodedDataLength) OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo; int errorcode = OSPC_ERR_NO_ERROR; if (ospvContentValue == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_INVALID_PARAMETER; OSPM_DBGERRORLOG(errorcode, "Null pointer supplied for return value"); } else if ((ospvEncodedData != OSPC_OSNULL) && (ospvEncodedDataLength == 0)) { errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; errorcode = OSPPASN1BufferCreate(eInfo->Content, eInfo->ContentLength, (OSPTASN1BUFFER **)&(eInfo->ContentValue)); } return errorcode; } /***************************************** UTCTIME ROUTINES *****************************************/ int OSPPASN1UTCTimeEncode( OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo; OSPTASN1BUFFER *buffer; int errorcode = OSPC_ERR_NO_ERROR; errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; buffer = (OSPTASN1BUFFER *)eInfo->ContentValue; eInfo->Content = buffer->Buffer; eInfo->ContentLength = buffer->BufferLength; } return errorcode; } int OSPPASN1UTCTimeDecode( void **osvpContentValue, unsigned char *ospvEncodedData, unsigned int ospvEncodedDataLength) OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo; int errorcode = OSPC_ERR_NO_ERROR; if (ospvContentValue == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_INVALID_PARAMETER; OSPM_DBGERRORLOG(errorcode, "Null pointer supplied for return value"); } else if ((ospvEncodedData != OSPC_OSNULL) && (ospvEncodedDataLength == 0)) { errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; errorcode = OSPPASN1BufferCreate(eInfo->Content, eInfo->ContentLength, (OSPTASN1BUFFER **)&(eInfo->ContentValue)); } return errorcode; } /***************************************** BIT STRING ROUTINES *****************************************/ int OSPPASN1BitStringDecode( void **osvpContentValue, unsigned char *ospvEncodedData, unsigned int ospvEncodedDataLength) OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo=OSPC_OSNULL; int errorcode = OSPC_ERR_NO_ERROR; OSPTASN1BITSTRING *buffer=OSPC_OSNULL; unsigned char *cptr=OSPC_OSNULL; unsigned unusedBits=0; unsigned length = 0; if (ospvContentValue == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_INVALID_PARAMETER; OSPM_DBGERRORLOG(errorcode, "Null pointer supplied for return value"); } else if ((ospvEncodedData != OSPC_OSNULL) && (ospvEncodedDataLength == 0)) { errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; cptr = eInfo->Content; /* First byte is #unused bits in last byte */ unusedBits = *cptr; length = eInfo->ContentLength; /* Create the Buffer */ errorcode = OSPPASN1BitStringCreate(cptr, length, unusedBits, &buffer); } return errorcode; } int OSPPASN1BitStringEncode( OSPTASN1ELEMENTINFO *ospvElementInfo) { OSPTASN1ELEMENTINFO *eInfo; OSPTASN1BITSTRING *bitString; int errorcode = OSPC_ERR_NO_ERROR; errorcode = OSPPASN1ElementTestContext(ospvElementInfo); if (errorcode == OSPC_ERR_NO_ERROR) { eInfo = ospvElementInfo; bitString = (OSPTASN1BITSTRING *)eInfo->ContentValue; eInfo->Content = bitString->Buffer->Buffer; eInfo->ContentLength = bitString->Buffer->BufferLength; } return errorcode; } int OSPPASN1BitStringCreate( unsigned char *ospvContent, unsigned ospvContentLength, unsigned ospvUnusedBits, OSPTASN1BITSTRING **ospvBitString) { int errorcode = OSPC_ERR_NO_ERROR; OSPTASN1BITSTRING *bitString; /* Allocate space for buffer structure */ OSPM_MALLOC(bitString, OSPTASN1BITSTRING, sizeof(OSPTASN1BITSTRING)); if (bitString == OSPC_OSNULL) { errorcode = OSPC_ERR_ASN1_UNABLE_TO_ALLOCATE_SPACE; OSPM_DBGERRORLOG(errorcode, "Unable to allocate an ASN1 BITSTRING"); } if (errorcode == OSPC_ERR_NO_ERROR) { /* Create a buffer containing bitstring contents */ errorcode = OSPPASN1BufferCreate(ospvContent,ospvContentLength, &(bitString->Buffer)); } /* Mkae sure buffer got created */ if (errorcode == OSPC_ERR_NO_ERROR) { /* Finish creating bit string buffer */ bitString->UnusedBits = ospvUnusedBits; *ospvBitString = bitString; } else { /* An error occured, get rid of allocated stuff - don't update ospvBitString ptr */ OSPM_FREE(bitString); } return errorcode; } void OSPPASN1BitStringDelete( OSPTASN1BITSTRING **ospvBitString) { /* Make sure the buffer exists */ if (*ospvBitString != OSPC_OSNULL) { /* Make sure storage exists */ if ((*ospvBitString)->Buffer != OSPC_OSNULL) { /* Delete the buffer */ OSPPASN1BufferDelete(&((*ospvBitString)->Buffer)); } /* Delete the buffer */ OSPM_FREE(*ospvBitString); } return; } #endif int OSPPASN1OctetStringEncode( OSPTASN1OBJECT **ospvEncodedObject, unsigned char *ospvData, unsigned int ospvDataLength, OSPEASN1DATAREFID ospvDataRefId) { int errorcode = OSPC_ERR_NO_ERROR; OSPTASN1ELEMENTINFO *eInfo = OSPC_OSNULL; OSPTASN1OBJECT *encodedObject = OSPC_OSNULL; unsigned char tag; /* Set up data and dataLength for octetstring - not much to do here */ tag = OSPC_TAG_TYPE_OCTET_STRING;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -