本文整理汇总了C++中OpcUa_InitializeStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ OpcUa_InitializeStatus函数的具体用法?C++ OpcUa_InitializeStatus怎么用?C++ OpcUa_InitializeStatus使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpcUa_InitializeStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpcUa_P_OpenSSL_AES_CBC_Encrypt
/*============================================================================
* OpcUa_P_OpenSSL_AES_CBC_Encrypt
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_OpenSSL_AES_CBC_Encrypt(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_Byte* a_pPlainText,
OpcUa_UInt32 a_plainTextLen,
OpcUa_Key* a_key,
OpcUa_Byte* a_pInitalVector,
OpcUa_Byte* a_pCipherText,
OpcUa_UInt32* a_pCipherTextLen)
{
AES_KEY key;
OpcUa_Byte pInitalVector[16];
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "AES_CBC_Encrypt");
OpcUa_ReferenceParameter(a_pProvider);
OpcUa_ReturnErrorIfArgumentNull(a_pPlainText);
OpcUa_ReturnErrorIfArgumentNull(a_key);
OpcUa_ReturnErrorIfArgumentNull(a_key->Key.Data);
OpcUa_ReturnErrorIfArgumentNull(a_pInitalVector);
OpcUa_ReturnErrorIfArgumentNull(a_pCipherTextLen);
if(a_plainTextLen % 16 != 0)
{
uStatus = OpcUa_BadInvalidArgument;
OpcUa_GotoErrorIfBad(uStatus);
}
*a_pCipherTextLen = a_plainTextLen;
/* if just the output length is needed for the caller of this function */
if(a_pCipherText == OpcUa_Null)
{
OpcUa_ReturnStatusCode;
}
/* we have to pass the key length in bits instead of bytes */
if(AES_set_encrypt_key(a_key->Key.Data, a_key->Key.Length * 8, &key) < 0)
{
uStatus = OpcUa_Bad;
OpcUa_GotoErrorIfBad(uStatus);
}
/* copy the IV because the AES_cbc_encrypt function overwrites it. */
OpcUa_P_Memory_MemCpy(pInitalVector, 16, a_pInitalVector, 16);
/* encrypt data */
AES_cbc_encrypt( a_pPlainText,
a_pCipherText,
a_plainTextLen,
&key,
pInitalVector,
AES_ENCRYPT);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
示例2: OpcUa_UadpPayloadHeader_WriteBinary
static
OpcUa_StatusCode OpcUa_UadpPayloadHeader_WriteBinary(OpcUa_UadpNetworkMessage* a_pValue, OpcUa_Byte **a_pBuffer, OpcUa_UInt32 *a_pSize)
{
OpcUa_Int32 ii;
OpcUa_InitializeStatus(OpcUa_Module_PubSub, "OpcUa_UadpPayloadHeader_WriteBinary");
OpcUa_ReturnErrorIfArgumentNull(a_pValue);
OpcUa_ReturnErrorIfArgumentNull(a_pBuffer);
OpcUa_ReturnErrorIfArgumentNull(*a_pBuffer);
OpcUa_ReturnErrorIfArgumentNull(a_pSize);
if(a_pValue->NetworkMessageHeader.NetworkMessageFlags & OpcUa_UadpNetworkMessageFlags_Chunk)
{
OpcUa_UadpEncode_Direct(UInt16, &a_pValue->Payload[0].Header.DataSetWriterId);
}
else
{
OpcUa_UadpEncode_Direct(Byte, &a_pValue->MessageCount);
for(ii = 0; ii < a_pValue->MessageCount; ii++)
{
OpcUa_UadpEncode_Direct(UInt16, &a_pValue->Payload[ii].Header.DataSetWriterId);
}
}
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
/* nothing to do */
OpcUa_FinishErrorHandling;
}
示例3: OpcUa_EnumeratedType_FindValue
/*============================================================================
* OpcUa_EnumeratedType_FindValue
*===========================================================================*/
OPCUA_EXPORT OpcUa_StatusCode OpcUa_EnumeratedType_FindValue(
OpcUa_EnumeratedType* a_pType,
OpcUa_StringA a_sName,
OpcUa_Int32* a_pValue)
{
OpcUa_UInt32 ii = 0;
OpcUa_InitializeStatus(OpcUa_Module_Serializer, "EnumeratedType_FindValue");
OpcUa_ReturnErrorIfArgumentNull(a_pType);
OpcUa_ReturnErrorIfArgumentNull(a_sName);
OpcUa_ReturnErrorIfArgumentNull(a_pValue);
*a_pValue = 0;
for (ii = 0; a_pType->Values[ii].Name != OpcUa_Null; ii++)
{
if (OpcUa_StrCmpA(a_pType->Values[ii].Name, a_sName) == 0)
{
*a_pValue = a_pType->Values[ii].Value;
break;
}
}
OpcUa_GotoErrorIfTrue(a_pType->Values[ii].Name == OpcUa_Null, OpcUa_BadInvalidArgument);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
/* nothing to do */
OpcUa_FinishErrorHandling;
}
示例4: OpcUa_P_RawSocket_Bind
/*============================================================================
* Bind to Socket
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_RawSocket_Bind( OpcUa_RawSocket a_RawSocket,
OpcUa_Int16 a_nPort)
{
OpcUa_Int32 intSize = 0;
SOCKET winSocket = (SOCKET)OPCUA_P_SOCKET_INVALID;
struct sockaddr_in srv;
struct sockaddr *pName;
OpcUa_InitializeStatus(OpcUa_Module_Socket, "P_Bind");
OpcUa_GotoErrorIfArgumentNull(a_RawSocket);
winSocket = (SOCKET)a_RawSocket;
intSize = sizeof(struct sockaddr_in);
OpcUa_MemSet(&srv, 0, intSize);
srv.sin_addr.s_addr = INADDR_ANY;
srv.sin_port = htons(a_nPort);
srv.sin_family = AF_INET;
pName = (struct sockaddr*)&srv;
if(bind(winSocket, pName, intSize) == OPCUA_P_SOCKET_SOCKETERROR)
{
uStatus = OpcUa_BadCommunicationError;
goto Error;
}
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
示例5: OpcUa_UadpGroupHeader_WriteBinary
static
OpcUa_StatusCode OpcUa_UadpGroupHeader_WriteBinary(OpcUa_UadpGroupHeader* a_pValue, OpcUa_Byte **a_pBuffer, OpcUa_UInt32 *a_pSize)
{
OpcUa_InitializeStatus(OpcUa_Module_PubSub, "OpcUa_UadpGroupHeader_WriteBinary");
OpcUa_ReturnErrorIfArgumentNull(a_pValue);
OpcUa_ReturnErrorIfArgumentNull(a_pBuffer);
OpcUa_ReturnErrorIfArgumentNull(*a_pBuffer);
OpcUa_ReturnErrorIfArgumentNull(a_pSize);
OpcUa_UadpEncode_Direct(Byte, &a_pValue->GroupFlags);
if(a_pValue->GroupFlags & OpcUa_UadpGroupHeader_EncodingBit_WriterGroupId)
{
OpcUa_UadpEncode_Direct(UInt16, &a_pValue->WriterGroupId);
}
if(a_pValue->GroupFlags & OpcUa_UadpGroupHeader_EncodingBit_GroupVersion)
{
OpcUa_UadpEncode_Direct(UInt32, &a_pValue->GroupVersion);
}
if(a_pValue->GroupFlags & OpcUa_UadpGroupHeader_EncodingBit_NetworkMessageNumber)
{
OpcUa_UadpEncode_Direct(UInt16, &a_pValue->NetworkMessageNumber);
}
if(a_pValue->GroupFlags & OpcUa_UadpGroupHeader_EncodingBit_SequenceNumber)
{
OpcUa_UadpEncode_Direct(UInt16, &a_pValue->SequenceNumber);
}
a_pValue->SequenceNumber++;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
/* nothing to do */
OpcUa_FinishErrorHandling;
}
示例6: OpcUa_TcpSecureChannel_CheckSequenceNumber
/*============================================================================
* OpcUa_TcpSecureChannel_CheckSequenceNumber
*===========================================================================*/
OpcUa_StatusCode OpcUa_TcpSecureChannel_CheckSequenceNumber(OpcUa_SecureChannel* a_pSecureChannel,
OpcUa_UInt32 a_uSequenceNumber)
{
OpcUa_InitializeStatus(OpcUa_Module_SecureChannel, "CheckSequenceNumber");
OpcUa_ReturnErrorIfArgumentNull(a_pSecureChannel);
OPCUA_SECURECHANNEL_LOCK(a_pSecureChannel);
/* The SequenceNumber shall also monotonically increase for all Messages
and shall not wrap around until it is greater than 4 294 966 271
(UInt32.MaxValue - 1 024). The first number after the wrap around
shall be less than 1 024. */
if(!((a_uSequenceNumber == a_pSecureChannel->uLastSequenceNumberRcvd + 1) ||
((a_uSequenceNumber < 1024) &&
(a_pSecureChannel->uLastSequenceNumberRcvd > 4294966271u))))
{
OpcUa_GotoErrorWithStatus(OpcUa_BadSequenceNumberInvalid);
}
a_pSecureChannel->uLastSequenceNumberRcvd = a_uSequenceNumber;
OPCUA_SECURECHANNEL_UNLOCK(a_pSecureChannel);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OPCUA_SECURECHANNEL_UNLOCK(a_pSecureChannel);
OpcUa_FinishErrorHandling;
}
示例7: OpcUa_P_OpenSSL_RSA_Private_Sign
/*
* ToDo: problems with RSA_PKCS1_OAEP_PADDING -> RSA_PKCS1_PSS_PADDING is
* needed (Version 0.9.9); RSA_PKCS1_OAEP_PADDING is just for encryption
*/
OpcUa_StatusCode OpcUa_P_OpenSSL_RSA_Private_Sign(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_ByteString a_data,
OpcUa_Key* a_privateKey,
OpcUa_Int16 a_padding, /* e.g. RSA_PKCS1_PADDING */
OpcUa_ByteString* a_pSignature) /* output length >= key length */
{
EVP_PKEY* pSSLPrivateKey = OpcUa_Null;
const unsigned char* pData = OpcUa_Null;
int iErr = 0;
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "RSA_Private_Sign");
/* unused parameters */
OpcUa_ReferenceParameter(a_pProvider);
OpcUa_ReferenceParameter(a_padding);
/* check parameters */
OpcUa_ReturnErrorIfArgumentNull(a_privateKey);
OpcUa_ReturnErrorIfArgumentNull(a_pSignature);
pData = a_privateKey->Key.Data;
OpcUa_ReturnErrorIfArgumentNull(pData);
OpcUa_ReturnErrorIfTrue((a_privateKey->Type != OpcUa_Crypto_KeyType_Rsa_Private), OpcUa_BadInvalidArgument);
/* convert private key and check key length against buffer length */
pSSLPrivateKey = d2i_PrivateKey(EVP_PKEY_RSA, OpcUa_Null, &pData, a_privateKey->Key.Length);
OpcUa_GotoErrorIfTrue((pSSLPrivateKey == OpcUa_Null), OpcUa_BadUnexpectedError);
OpcUa_GotoErrorIfTrue((a_pSignature->Length < RSA_size(pSSLPrivateKey->pkey.rsa)), OpcUa_BadInvalidArgument);
/* sign data */
iErr = RSA_sign(NID_sha1, a_data.Data, a_data.Length, a_pSignature->Data, (unsigned int*)&a_pSignature->Length, pSSLPrivateKey->pkey.rsa);
OpcUa_GotoErrorIfTrue((iErr != 1), OpcUa_BadUnexpectedError);
/* free internal key representation */
EVP_PKEY_free(pSSLPrivateKey);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
if(OpcUa_IsEqual(OpcUa_BadUnexpectedError))
{
long lErr = ERR_get_error();
char* szErr = ERR_error_string(lErr, 0);
if(szErr != OpcUa_Null)
{
OpcUa_P_Trace("*** RSA_Private_Sign: ");
OpcUa_P_Trace(szErr);
OpcUa_P_Trace(" ***\n");
}
}
if(pSSLPrivateKey != OpcUa_Null)
{
EVP_PKEY_free(pSSLPrivateKey);
}
OpcUa_FinishErrorHandling;
}
示例8: OpcUa_P_SocketUdp_CreateSender
/*============================================================================
* Create a UDP sender socket
*===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_P_SocketUdp_CreateSender( OpcUa_StringA a_LocalIpAddress,
OpcUa_StringA a_RemoteIpAddress,
OpcUa_Int16 a_RemotePort,
OpcUa_Byte a_TimeToLive,
OpcUa_Socket* a_pSocket)
{
OpcUa_InternalUdpSocket* pInternalSocket = OpcUa_Null;
OpcUa_InitializeStatus(OpcUa_Module_Socket, "CreateUdpSender");
OpcUa_ReturnErrorIfArgumentNull(a_pSocket);
*a_pSocket = OpcUa_Null;
OpcUa_GotoErrorIfArgumentNull(a_RemoteIpAddress);
if(a_RemotePort == 0)
{
OpcUa_GotoErrorWithStatus(OpcUa_BadInvalidArgument);
}
pInternalSocket = (OpcUa_InternalUdpSocket*)OpcUa_P_Memory_Alloc(sizeof(OpcUa_InternalUdpSocket));
OpcUa_GotoErrorIfAllocFailed(pInternalSocket);
pInternalSocket->pSocketServiceTable = &OpcUa_UdpSocketServiceTable;
if(strchr(a_RemoteIpAddress, ':'))
{
uStatus = OpcUa_P_RawSocket_CreateUdpV6(&pInternalSocket->rawSocket,
OpcUa_True,
a_LocalIpAddress,
a_RemoteIpAddress,
a_RemotePort,
a_TimeToLive);
OpcUa_GotoErrorIfBad(uStatus);
}
else
{
uStatus = OpcUa_P_RawSocket_CreateUdp(&pInternalSocket->rawSocket,
OpcUa_True,
a_LocalIpAddress,
a_RemoteIpAddress,
a_RemotePort,
a_TimeToLive);
OpcUa_GotoErrorIfBad(uStatus);
}
*a_pSocket = pInternalSocket;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
if(pInternalSocket != OpcUa_Null)
{
OpcUa_P_Memory_Free(pInternalSocket);
}
OpcUa_FinishErrorHandling;
}
示例9: OpcUa_P_OpenSSL_X509_GetSignature
/*============================================================================
* OpcUa_P_OpenSSL_X509_GetSignature
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_OpenSSL_X509_GetSignature(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_ByteString* a_pCertificate,
OpcUa_Signature* a_pSignature)
{
X509* pX509Certificate = OpcUa_Null;
const unsigned char* pTemp = OpcUa_Null;
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "X509_GetSignature");
OpcUa_ReferenceParameter(a_pProvider);
OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
OpcUa_ReturnErrorIfArgumentNull(a_pCertificate);
OpcUa_ReturnErrorIfArgumentNull(a_pSignature);
/* d2i_X509 modifies the given pointer -> use local replacement */
pTemp = a_pCertificate->Data;
d2i_X509(&pX509Certificate, &pTemp, a_pCertificate->Length);
if(pX509Certificate == OpcUa_Null)
{
uStatus = OpcUa_Bad;
OpcUa_GotoErrorIfBad(uStatus);
}
a_pSignature->Signature.Length = pX509Certificate->signature->length;
a_pSignature->Algorithm = OBJ_obj2nid(pX509Certificate->sig_alg->algorithm);
if(a_pSignature->Algorithm == NID_undef)
{
uStatus = OpcUa_Bad;
OpcUa_GotoErrorIfBad(uStatus);
}
if(a_pSignature->Signature.Data != OpcUa_Null)
{
uStatus = OpcUa_P_Memory_MemCpy(a_pSignature->Signature.Data,
a_pSignature->Signature.Length,
pX509Certificate->signature->data,
pX509Certificate->signature->length);
}
X509_free(pX509Certificate);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
if(pX509Certificate != OpcUa_Null)
{
X509_free(pX509Certificate);
}
OpcUa_FinishErrorHandling;
}
示例10: OpcUa_P_OpenSSL_RSA_GenerateKeys
/*============================================================================
* OpcUa_P_OpenSSL_RSA_GenerateKeys
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_OpenSSL_RSA_GenerateKeys(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_UInt32 a_bits,
OpcUa_Key* a_pPublicKey,
OpcUa_Key* a_pPrivateKey)
{
RSA* pRsa;
unsigned char* pData;
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "RSA_GenerateKeys");
OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
OpcUa_ReturnErrorIfArgumentNull(a_pPublicKey);
OpcUa_ReturnErrorIfArgumentNull(a_pPrivateKey);
OpcUa_ReferenceParameter(a_pProvider);
/* Just 1024 or 2048 bits should be allowed for compatibility reasons */
if ((a_bits != 1024) && (a_bits != 2048) && (a_bits != 3072) && (a_bits != 4096))
{
uStatus = OpcUa_BadInvalidArgument;
OpcUa_GotoErrorIfBad(uStatus);
}
if(a_pPublicKey->Key.Data == OpcUa_Null)
{
a_pPublicKey->Key.Length = a_bits;
OpcUa_ReturnStatusCode;
}
if(a_pPrivateKey->Key.Data == OpcUa_Null)
{
a_pPrivateKey->Key.Length = a_bits;
OpcUa_ReturnStatusCode;
}
pRsa = RSA_generate_key(a_bits, RSA_F4, NULL, OpcUa_Null);
pData = a_pPublicKey->Key.Data;
a_pPublicKey->Key.Length = i2d_RSAPublicKey(pRsa, &pData);
pData = a_pPrivateKey->Key.Data;
a_pPrivateKey->Key.Length = i2d_RSAPrivateKey(pRsa, &pData);
/* clean up */
if(pRsa != OpcUa_Null)
{
RSA_free(pRsa);
}
a_pPublicKey->Type = OpcUa_Crypto_Rsa_Alg_Id;
a_pPrivateKey->Type = OpcUa_Crypto_Rsa_Alg_Id;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
示例11: OpcUa_P_OpenSSL_RSA_Public_Verify
/*
ToDo: problems with RSA_PKCS1_OAEP_PADDING -> find solution
*/
OpcUa_StatusCode OpcUa_P_OpenSSL_RSA_Public_Verify(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_ByteString a_data,
OpcUa_Key* a_publicKey,
OpcUa_Int16 a_padding,
OpcUa_ByteString* a_pSignature)
{
EVP_PKEY* pPublicKey = OpcUa_Null;
OpcUa_Int32 keySize = 0;
const unsigned char *pData;
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "RSA_Public_Verify");
OpcUa_ReferenceParameter(a_pProvider);
OpcUa_ReferenceParameter(a_padding);
OpcUa_ReturnErrorIfArgumentNull(a_data.Data);
OpcUa_ReturnErrorIfArgumentNull(a_publicKey);
OpcUa_ReturnErrorIfArgumentNull(a_publicKey->Key.Data);
OpcUa_ReturnErrorIfArgumentNull(a_pSignature);
if(a_publicKey->Type != OpcUa_Crypto_KeyType_Rsa_Public)
{
OpcUa_GotoErrorWithStatus(OpcUa_BadInvalidArgument);
}
pData = a_publicKey->Key.Data;
pPublicKey = d2i_PublicKey(EVP_PKEY_RSA,OpcUa_Null, &pData, a_publicKey->Key.Length);
if(pPublicKey == OpcUa_Null)
{
OpcUa_GotoErrorWithStatus(OpcUa_BadInvalidArgument);
}
keySize = RSA_size(pPublicKey->pkey.rsa);
if((a_pSignature->Length%keySize) != 0)
{
OpcUa_GotoErrorWithStatus(OpcUa_Bad);
}
if (RSA_verify(NID_sha1, a_data.Data, a_data.Length, a_pSignature->Data, a_pSignature->Length, pPublicKey->pkey.rsa) != 1)
{
OpcUa_GotoErrorWithStatus(OpcUa_Bad);
}
EVP_PKEY_free(pPublicKey);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
if (pPublicKey != OpcUa_Null)
{
EVP_PKEY_free(pPublicKey);
}
OpcUa_FinishErrorHandling;
}
示例12: OpcUa_P_RawSocket_Connect
/*============================================================================
* Connect Socket for Client.
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_RawSocket_Connect( OpcUa_RawSocket a_RawSocket,
OpcUa_Int16 a_nPort,
OpcUa_StringA a_sHost)
{
int intSize = 0;
SOCKET winSocket = (SOCKET)OPCUA_P_SOCKET_INVALID;
struct sockaddr *pName;
struct sockaddr_in srv;
char* localhost = "127.0.0.1";
OpcUa_InitializeStatus(OpcUa_Module_Socket, "P_Connect");
OpcUa_GotoErrorIfArgumentNull(a_RawSocket);
winSocket = (SOCKET)a_RawSocket;
intSize = sizeof(struct sockaddr_in);
OpcUa_MemSet(&srv, 0, intSize);
if(!strcmp("localhost", a_sHost))
{
a_sHost = localhost;
}
srv.sin_addr.s_addr = inet_addr(a_sHost);
if(srv.sin_addr.s_addr == INADDR_NONE)
{
return OpcUa_BadInvalidArgument;
}
srv.sin_port = htons(a_nPort);
srv.sin_family = AF_INET;
pName = (struct sockaddr *) &srv;
if(connect(winSocket, pName, intSize) == OPCUA_P_SOCKET_SOCKETERROR)
{
int result = OpcUa_P_RawSocket_GetLastError((OpcUa_RawSocket)winSocket);
/* a connect takes some time and this "error" is common with nonblocking sockets */
if(result == WSAEWOULDBLOCK || result == WSAEINPROGRESS)
{
uStatus = OpcUa_BadWouldBlock;
}
else
{
uStatus = OpcUa_BadCommunicationError;
}
goto Error;
}
uStatus = OpcUa_Good;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
示例13: OpcUa_P_OpenSSL_Random_Key_Generate
/*============================================================================
* OpcUa_P_OpenSSL_Random_Key_Generate
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_OpenSSL_Random_Key_Generate(
OpcUa_CryptoProvider* a_pProvider,
OpcUa_Int32 a_keyLen,
OpcUa_Key* a_pKey)
{
OpcUa_CryptoProviderConfig* pConfig = OpcUa_Null;
OpcUa_Int32 keyLen = 0;
OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "Random_Key_Generate");
OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
OpcUa_ReturnErrorIfArgumentNull(a_pKey);
OpcUa_ReferenceParameter(a_pProvider);
keyLen = a_keyLen;
if(keyLen < 0)
{
if(a_pProvider->Handle != OpcUa_Null)
{
/* get default configuration */
pConfig = (OpcUa_CryptoProviderConfig*)a_pProvider->Handle;
keyLen = pConfig->SymmetricKeyLength;
}
else
{
uStatus = OpcUa_BadInvalidArgument;
OpcUa_GotoErrorIfBad(uStatus);
}
}
else if(keyLen > MAX_GENERATED_OUTPUT_LEN)
{
uStatus = OpcUa_BadInvalidArgument;
OpcUa_GotoErrorIfBad(uStatus);
}
a_pKey->Key.Length = keyLen;
a_pKey->Type = OpcUa_Crypto_KeyType_Random;
if(a_pKey->Key.Data == OpcUa_Null)
{
OpcUa_ReturnStatusCode;
}
if(RAND_bytes(a_pKey->Key.Data, a_pKey->Key.Length) == 0)
{
uStatus = OpcUa_Bad;
OpcUa_GotoErrorIfBad(uStatus);
}
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
示例14: OpcUa_P_SocketManager_NewSignalSocket
/*============================================================================
* Create a new signal socket
*===========================================================================*/
OpcUa_StatusCode OpcUa_P_SocketManager_NewSignalSocket(OpcUa_SocketManager a_pSocketManager)
{
OpcUa_InternalSocket* pIntSignalSocket = OpcUa_Null;
OpcUa_InternalSocketManager* pInternalSocketManager = (OpcUa_InternalSocketManager*)a_pSocketManager;
OpcUa_InitializeStatus(OpcUa_Module_Socket, "NewSignalSocket");
OpcUa_GotoErrorIfArgumentNull(a_pSocketManager);
pIntSignalSocket = (OpcUa_InternalSocket*)OpcUa_SocketManager_FindFreeSocket(a_pSocketManager, OpcUa_True);
if(pIntSignalSocket == OpcUa_Null)
{
uStatus = OpcUa_BadResourceUnavailable;
goto Error;
}
uStatus = OpcUa_P_RawSocket_CreateSocketPair( &pIntSignalSocket->rawSocket,
&pInternalSocketManager->pCookie);
OpcUa_GotoErrorIfBad(uStatus);
pIntSignalSocket->Flags.EventMask = OPCUA_SOCKET_CLOSE_EVENT
| OPCUA_SOCKET_READ_EVENT
| OPCUA_SOCKET_EXCEPT_EVENT
| OPCUA_SOCKET_TIMEOUT_EVENT;
uStatus = OpcUa_P_RawSocket_SetBlockMode (pIntSignalSocket->rawSocket, OpcUa_False);
if (OpcUa_IsBad(uStatus))
{
OpcUa_P_RawSocket_Close(pIntSignalSocket->rawSocket);
OpcUa_P_RawSocket_Close(pInternalSocketManager->pCookie);
OpcUa_GotoErrorWithStatus(uStatus);
}
uStatus = OpcUa_P_RawSocket_SetBlockMode (pInternalSocketManager->pCookie, OpcUa_False);
if (OpcUa_IsBad(uStatus))
{
OpcUa_P_RawSocket_Close(pIntSignalSocket->rawSocket);
OpcUa_P_RawSocket_Close(pInternalSocketManager->pCookie);
OpcUa_GotoErrorWithStatus(uStatus);
}
OPCUA_SOCKET_SETVALID(pIntSignalSocket);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
if(pIntSignalSocket)
{
pIntSignalSocket->rawSocket = (OpcUa_RawSocket)OPCUA_P_SOCKET_INVALID;
OPCUA_SOCKET_INVALIDATE(pIntSignalSocket);
}
OpcUa_FinishErrorHandling;
}
示例15: OpcUa_P_Socket_CleanupNetwork
/*============================================================================
* Clean the platform network interface up.
*===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_P_Socket_CleanupNetwork(OpcUa_Void)
{
OpcUa_InitializeStatus(OpcUa_Module_Socket, "CleanupNetwork");
/* cleanup platform networking */
uStatus = OpcUa_P_RawSocket_CleanupNetwork();
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}