void ZoomNavigator::OnPreviewClicked(wxMouseEvent& e) { IEditor* curEditor = m_mgr->GetActiveEditor(); // user clicked on the preview CHECK_CONDITION(m_startupCompleted); CHECK_CONDITION(curEditor); CHECK_CONDITION(m_enabled); // the first line is taken from the preview int pos = m_text->PositionFromPoint(e.GetPosition()); if(pos == wxSTC_INVALID_POSITION) { return; } int first = m_text->LineFromPosition(pos); int nLinesOnScreen = curEditor->GetCtrl()->LinesOnScreen(); first -= (nLinesOnScreen / 2); if(first < 0) first = 0; // however, the last line is set according to the actual editor int last = nLinesOnScreen + first; PatchUpHighlights(first, last); curEditor->GetCtrl()->SetFirstVisibleLine(first); curEditor->SetCaretAt(curEditor->PosFromLine(first + (nLinesOnScreen / 2))); // reset the from/last members to avoid unwanted movements in the 'OnTimer' function m_markerFirstLine = curEditor->GetCtrl()->GetFirstVisibleLine(); m_markerLastLine = m_markerFirstLine + curEditor->GetCtrl()->LinesOnScreen(); }
void ZoomNavigator::DoUpdate() { // sanity tests CHECK_CONDITION(m_enabled); CHECK_CONDITION(!m_mgr->IsShutdownInProgress()); IEditor* curEditor = m_mgr->GetActiveEditor(); if(!curEditor && !m_text->IsEmpty()) { DoCleanup(); } CHECK_CONDITION(curEditor); wxStyledTextCtrl* stc = curEditor->GetCtrl(); CHECK_CONDITION(stc); if(curEditor->GetFileName().GetFullPath() != m_curfile) { SetEditorText(curEditor); } int first = stc->GetFirstVisibleLine(); int last = stc->LinesOnScreen() + first; if(m_markerFirstLine != first || m_markerLastLine != last) { PatchUpHighlights(first, last); SetZoomTextScrollPosToMiddle(stc); } }
const config_file::value& config_file::value::operator[](const char* rec_name) const { CHECK_CONDITION(this->type_ == RECORD, "Not a record type"); mapci it = record_.find(rec_name); CHECK_CONDITION(it != this->record_.end(), "Record not found"); return it->second; }
bool AES_KW_Encrypt(COSE_RecipientInfo * pcose, const byte * pbKeyIn, int cbitKey, const byte * pbContent, int cbContent, cose_errback * perr) { byte *pbOut = NULL; AES_KEY key; #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pcose->m_encrypt.m_message.m_allocContext; #endif cn_cbor * cnTmp = NULL; pbOut = COSE_CALLOC(cbContent + 8, 1, context); CHECK_CONDITION(AES_set_encrypt_key(pbKeyIn, cbitKey, &key) == 0, COSE_ERR_CRYPTO_FAIL); CHECK_CONDITION(AES_wrap_key(&key, NULL, pbOut, pbContent, cbContent), COSE_ERR_CRYPTO_FAIL); cnTmp = cn_cbor_data_create(pbOut, (int)cbContent + 8, CBOR_CONTEXT_PARAM_COMMA NULL); CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR); pbOut = NULL; CHECK_CONDITION(_COSE_array_replace(&pcose->m_encrypt.m_message, cnTmp, INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_ERR_CBOR); cnTmp = NULL; return true; errorReturn: COSE_FREE(cnTmp, context); if (pbOut != NULL) COSE_FREE(pbOut, context); return false; }
const config_file::value& config_file::value::operator[](size_t index) const { CHECK_CONDITION(this->type_ == ARRAY, "Not an array type"); CHECK_CONDITION(index < this->array_.size() && index>=0, "Array out of range"); return this->array_[index]; }
// Function Specification // // Name: errlTestTime // // Description: errlTestTime // // End Function Specification uint32_t errlTestTime() { uint32_t l_rc = 0; do { ERRL_DBG("START"); errlHndl_t l_handle = NULL; uint64_t l_start = 0; uint64_t l_end = 0; /****************************************************/ // Check timeStamp // Create one log l_start = ssx_timebase_get(); l_handle = createErrl( 0x1716, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 128, 0x1, 0x2); CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); // check time stamp errlHndl_t l_handle2 = l_handle; commitErrl( &l_handle ); l_end = ssx_timebase_get(); CHECK_CONDITION( (l_handle2->iv_userDetails.iv_timeStamp >= l_start) && (l_handle2->iv_userDetails.iv_timeStamp <= l_end ), l_rc); deleteErrl(&l_handle2); ERRL_DBG("END \n"); }while(0); return l_rc; }
bool ECDSA_Sign(COSE * pSigner, int index, const cn_cbor * pKey, int cbitDigest, const byte * rgbToSign, size_t cbToSign, cose_errback * perr) { EC_KEY * eckey = NULL; byte rgbDigest[EVP_MAX_MD_SIZE]; unsigned int cbDigest = sizeof(rgbDigest); byte * pbSig = NULL; const EVP_MD * digest; #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pSigner->m_allocContext; #endif cn_cbor * p = NULL; ECDSA_SIG * psig = NULL; cn_cbor_errback cbor_error; int cbR; byte rgbSig[66]; int cb; eckey = ECKey_From(pKey, &cbR, perr); if (eckey == NULL) { errorReturn: if (p != NULL) CN_CBOR_FREE(p, context); if (eckey != NULL) EC_KEY_free(eckey); return false; } switch (cbitDigest) { case 256: digest = EVP_sha256(); break; case 512: digest = EVP_sha512(); break; case 384: digest = EVP_sha384(); break; default: FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER); } EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, NULL); psig = ECDSA_do_sign(rgbDigest, cbDigest, eckey); CHECK_CONDITION(psig != NULL, COSE_ERR_CRYPTO_FAIL); pbSig = COSE_CALLOC(cbR, 2, context); CHECK_CONDITION(pbSig != NULL, COSE_ERR_OUT_OF_MEMORY); cb = BN_bn2bin(psig->r, rgbSig); CHECK_CONDITION(cb <= cbR, COSE_ERR_INVALID_PARAMETER); memcpy(pbSig + cbR - cb, rgbSig, cb); cb = BN_bn2bin(psig->s, rgbSig); CHECK_CONDITION(cb <= cbR, COSE_ERR_INVALID_PARAMETER); memcpy(pbSig + 2*cbR - cb, rgbSig, cb); p = cn_cbor_data_create(pbSig, cbR*2, CBOR_CONTEXT_PARAM_COMMA &cbor_error); CHECK_CONDITION_CBOR(p != NULL, cbor_error); CHECK_CONDITION(_COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_ERR_CBOR); return true; }
bool COSE_Enveloped_SetContent(HCOSE_ENVELOPED h, const byte * rgb, size_t cb, cose_errback * perr) { CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(rgb != NULL, COSE_ERR_INVALID_PARAMETER); return _COSE_Enveloped_SetContent((COSE_Enveloped *)h, rgb, cb, perr); errorReturn: return false; }
bool COSE_Enveloped_SetExternal(HCOSE_ENVELOPED hcose, const byte * pbExternalData, size_t cbExternalData, cose_errback * perr) { CHECK_CONDITION(IsValidEnvelopedHandle(hcose), COSE_ERR_INVALID_HANDLE) CHECK_CONDITION((pbExternalData != NULL) || (cbExternalData == 0), COSE_ERR_INVALID_PARAMETER); return _COSE_SetExternal(&((COSE_Enveloped *)hcose)->m_message, pbExternalData, cbExternalData, perr); errorReturn: return false; }
bool COSE_Enveloped_map_put_int(HCOSE_ENVELOPED h, int key, cn_cbor * value, int flags, cose_errback * perr) { CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER); return _COSE_map_put(&((COSE_Enveloped *)h)->m_message, key, value, flags, perr); errorReturn: return false; }
bool COSE_Encrypt_encrypt(HCOSE_ENCRYPT h, const byte * pbKey, size_t cbKey, cose_errback * perr) { CHECK_CONDITION(IsValidEncryptHandle(h), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(pbKey != NULL, COSE_ERR_INVALID_PARAMETER); return _COSE_Enveloped_encrypt((COSE_Encrypt *)h, pbKey, cbKey, "Encrypt0", perr); errorReturn: return false; }
bool _COSE_Encrypt_Build_AAD(COSE * pMessage, byte ** ppbAAD, size_t * pcbAAD, const char * szContext, cose_errback * perr) { #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pMessage->m_allocContext; #endif cn_cbor_errback cbor_error; byte * pbAuthData; size_t cbAuthData; cn_cbor * pAuthData; cn_cbor * pItem; cn_cbor * ptmp = NULL; // Build authenticated data pbAuthData = NULL; pAuthData = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error); CHECK_CONDITION_CBOR(pAuthData != NULL, cbor_error); ptmp = cn_cbor_string_create(szContext, CBOR_CONTEXT_PARAM_COMMA &cbor_error); CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error); CHECK_CONDITION_CBOR(cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error); ptmp = NULL; pItem = _COSE_arrayget_int(pMessage, INDEX_PROTECTED); CHECK_CONDITION(pItem != NULL, COSE_ERR_INVALID_PARAMETER); if ((pItem->length == 1) && (pItem->v.bytes[0] == 0xa0)) { ptmp = cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA &cbor_error); } else { ptmp = cn_cbor_data_create(pItem->v.bytes, (int)pItem->length, CBOR_CONTEXT_PARAM_COMMA &cbor_error); } CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error); CHECK_CONDITION_CBOR(cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error); ptmp = NULL; ptmp = cn_cbor_data_create(pMessage->m_pbExternal, (int) pMessage->m_cbExternal, CBOR_CONTEXT_PARAM_COMMA &cbor_error); CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error); CHECK_CONDITION_CBOR(cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error); ptmp = NULL; cbAuthData = cn_cbor_encoder_write(RgbDontUse, 0, sizeof(RgbDontUse), pAuthData); pbAuthData = (byte *)COSE_CALLOC(cbAuthData, 1, context); CHECK_CONDITION(pbAuthData != NULL, COSE_ERR_OUT_OF_MEMORY); CHECK_CONDITION((size_t)cn_cbor_encoder_write(pbAuthData, 0, cbAuthData, pAuthData) == cbAuthData, COSE_ERR_CBOR); *ppbAAD = pbAuthData; *pcbAAD = cbAuthData; return true; errorReturn: if (pbAuthData != NULL) COSE_FREE(pbAuthData, context); if (ptmp != NULL) CN_CBOR_FREE(ptmp, NULL); if (pAuthData != NULL) CN_CBOR_FREE(pAuthData, context); return false; }
bool COSE_Enveloped_encrypt(HCOSE_ENVELOPED h, cose_errback * perr) { COSE_Enveloped * pcose = (COSE_Enveloped *)h; CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(pcose->m_recipientFirst != NULL, COSE_ERR_INVALID_HANDLE); return _COSE_Enveloped_encrypt(pcose, NULL, 0, "Encrypt", perr); errorReturn: return false; }
TEST(ModelBase, SimpleModelCreation) { Model model; CHECK_CONDITION( model.root() == nullptr ); TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode")); CHECK_CONDITION( model.root() == root ); CHECK_CONDITION( root->model() == &model ); CHECK_CONDITION( root->name()->model() == &model ); }
TEST(OOModel, SimpleClassTest) { Model::Model model; Class* root = dynamic_cast<Class*> (model.createRoot("Class")); CHECK_CONDITION(root != nullptr); CHECK_CONDITION(root->name().isEmpty()); model.beginModification(root, "setName"); root->setName("Test"); model.endModification(); CHECK_STR_EQUAL("Test", root->name()); }
TEST(OOModel, SimpleProjectTest) { Model::Model model; Project* root = dynamic_cast<Project*> (model.createRoot("Project")); CHECK_CONDITION(root != nullptr); CHECK_CONDITION(root->name().isEmpty()); model.beginModification(root, "setName"); root->setName("prj"); model.endModification(); CHECK_STR_EQUAL("prj", root->name()); }
pipeline_data_queue::~pipeline_data_queue() { while(!free_list_.empty()){ delete free_list_.front(); free_list_.pop_front(); } while(!active_queue_.empty()){ delete active_queue_.front(); active_queue_.pop_front(); } CHECK_CONDITION(active_queue_.empty(), "active_queue_ not properly destroyed"); CHECK_CONDITION(free_list_.empty(), "free_list_ not properly destroyed"); }
bool AES_CBC_MAC_Validate(COSE_MacMessage * pcose, int TSize, const byte * pbKey, size_t cbKey, const byte * pbAuthData, size_t cbAuthData, cose_errback * perr) { const EVP_CIPHER * pcipher = NULL; EVP_CIPHER_CTX ctx; int cbOut; byte rgbIV[16] = { 0 }; byte rgbTag[16] = { 0 }; bool f = false; unsigned int i; switch (cbKey*8) { case 128: pcipher = EVP_aes_128_cbc(); break; case 256: pcipher = EVP_aes_256_cbc(); break; default: FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER); } // Setup and run the OpenSSL code EVP_CIPHER_CTX_init(&ctx); CHECK_CONDITION(EVP_EncryptInit_ex(&ctx, pcipher, NULL, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL); TSize /= 8; for (i = 0; i < (unsigned int) cbAuthData / 16; i++) { CHECK_CONDITION(EVP_EncryptUpdate(&ctx, rgbTag, &cbOut, pbAuthData+(i*16), 16), COSE_ERR_CRYPTO_FAIL); } if (cbAuthData % 16 != 0) { CHECK_CONDITION(EVP_EncryptUpdate(&ctx, rgbTag, &cbOut, pbAuthData + (i * 16), cbAuthData % 16), COSE_ERR_CRYPTO_FAIL); CHECK_CONDITION(EVP_EncryptUpdate(&ctx, rgbTag, &cbOut, rgbIV, 16 - (cbAuthData % 16)), COSE_ERR_CRYPTO_FAIL); } cn_cbor * cn = _COSE_arrayget_int(&pcose->m_message, INDEX_MAC_TAG); CHECK_CONDITION(cn != NULL, COSE_ERR_CBOR); for (i = 0; i < (unsigned int)TSize; i++) f |= (cn->v.bytes[i] != rgbTag[i]); EVP_CIPHER_CTX_cleanup(&ctx); return !f; errorReturn: EVP_CIPHER_CTX_cleanup(&ctx); return false; }
bool ECDSA_Verify(COSE * pSigner, int index, const cn_cbor * pKey, int cbitDigest, const byte * rgbToSign, size_t cbToSign, cose_errback * perr) { EC_KEY * eckey = NULL; byte rgbDigest[EVP_MAX_MD_SIZE]; unsigned int cbDigest = sizeof(rgbDigest); const EVP_MD * digest; #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pSigner->m_allocContext; #endif cn_cbor * p = NULL; ECDSA_SIG sig = { NULL, NULL }; int cbR; cn_cbor * pSig; size_t cbSignature; eckey = ECKey_From(pKey, &cbR, perr); if (eckey == NULL) { errorReturn: if (sig.r != NULL) BN_free(sig.r); if (sig.s != NULL) BN_free(sig.s); if (p != NULL) CN_CBOR_FREE(p, context); if (eckey != NULL) EC_KEY_free(eckey); return false; } switch (cbitDigest) { case 256: digest = EVP_sha256(); break; case 512: digest = EVP_sha512(); break; case 384: digest = EVP_sha384(); break; default: FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER); } EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, NULL); pSig = _COSE_arrayget_int(pSigner, index); CHECK_CONDITION(pSig != NULL, CN_CBOR_ERR_INVALID_PARAMETER); cbSignature = pSig->length; CHECK_CONDITION(cbSignature / 2 == cbR, COSE_ERR_INVALID_PARAMETER); sig.r = BN_bin2bn(pSig->v.bytes,(int) cbSignature/2, NULL); sig.s = BN_bin2bn(pSig->v.bytes+cbSignature/2, (int) cbSignature/2, NULL); CHECK_CONDITION(ECDSA_do_verify(rgbDigest, cbDigest, &sig, eckey) == 1, COSE_ERR_CRYPTO_FAIL); BN_free(sig.r); BN_free(sig.s); if (eckey != NULL) EC_KEY_free(eckey); return true; }
/////////////////////////////////////////////////////////////////////////////// // // ConstructWriterDefinition // /////////////////////////////////////////////////////////////////////////////// bool ConstructWriterDefinition( __in IVssCreateExpressWriterMetadata *pMetadata ) { HRESULT hr = S_OK; bool bResult = false; PCWSTR wszComponent = L"SampleComponent"; wprintf(L"INFO: ConstructWriterDefinition called\n"); // // Select restore method // wprintf(L"INFO: Selecting restore method...\n"); CHECK_CONDITION( SetRestoreMethod( pMetadata, VSS_RME_RESTORE_IF_CAN_REPLACE, // VSS_RESTOREMETHOD_ENUM NULL, // Service name, if method is VSS_RME_STOP_RESTORE_RESTART false), // Reboot required L"SetRestoreMethod failed"); // // Add components and files // wprintf(L"INFO: Adding basic component...\n"); CHECK_CONDITION( AddComponent( pMetadata, VSS_CT_FILEGROUP, // VSS_COMPONENT_TYPE wszComponent), // Component name L"AddComponent failed"); CHECK_CONDITION( AddFilesToFileGroup( pMetadata, wszComponent, // Component name L"c:\\xwdata", // Directory covered L"*.*", // Files covered true, // Recursive VSS_FSBT_ALL_SNAPSHOT_REQUIRED | VSS_FSBT_FULL_BACKUP_REQUIRED), // Backup type mask L"AddFilesToFileGroup failed"); bResult = true; _exit: return bResult; }
TEST(FilePersistence, LoadMultipleUnits) { QString testDir = ":/FilePersistence/test/persisted"; Model::Model model; FileStore store; store.setBaseFolder(testDir); model.load(&store, "units"); TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root()); CHECK_STR_EQUAL("BinaryNode", root->typeName() ); CHECK_STR_EQUAL("Root", root->name()->get() ); CHECK_CONDITION(root->left() != nullptr); CHECK_CONDITION(root->right() != nullptr); CHECK_STR_EQUAL("BinaryNodePersistenceUnit", root->left()->typeName() ); CHECK_STR_EQUAL("Left child", root->left()->name()->get() ); CHECK_CONDITION(root->left()->left() != nullptr); CHECK_CONDITION(root->left()->right() == nullptr); CHECK_STR_EQUAL("BinaryNode", root->left()->left()->typeName() ); CHECK_STR_EQUAL("in a new unit", root->left()->left()->name()->get() ); CHECK_CONDITION(root->left()->left()->left() == nullptr); CHECK_CONDITION(root->left()->left()->right() == nullptr); CHECK_STR_EQUAL("BinaryNode", root->right()->typeName() ); CHECK_STR_EQUAL("Right child", root->right()->name()->get() ); CHECK_CONDITION(root->right()->left() == nullptr); CHECK_CONDITION(root->right()->right() == nullptr); }
/////////////////////////////////////////////////////////////////////////////// // // CreateAndSaveToFile // /////////////////////////////////////////////////////////////////////////////// bool CreateAndSaveToFile() { HRESULT hr = S_OK; bool bResult = false; CComPtr<IVssExpressWriter> spExpressWriter; CComPtr<IVssCreateExpressWriterMetadata> spMetadata; wprintf(L"INFO: CreateAndSaveToFile called\n"); // // Create Express Writer // wprintf(L"INFO: Creating Express Writer...\n"); CHECK_HR( CreateVssExpressWriter(&spExpressWriter), L"CreateVssExpressWriter failed"); // // Create metadata // wprintf(L"INFO: Creating metadata...\n"); CHECK_HR( spExpressWriter->CreateMetadata( EXPRESS_WRITER_SAMPLE_GUID, // Express Writer GUID L"Sample Express Writer", // Express Writer friendly name VSS_UT_BOOTABLESYSTEMSTATE, // VSS_USAGE_TYPE 1, // Major version 0, // Minor version 0, // Reserved (must be 0) &spMetadata), L"CreateVssExpressWriter failed"); CHECK_CONDITION( ConstructWriterDefinition(spMetadata), L"ConstructWriterDefinition failed"); bResult = true; // // Save results // CHECK_CONDITION(SaveToFile(spMetadata, g_wszFileName), L"SaveToFile failed"); bResult = true; _exit: return bResult; }
// Function Specification // // Name: errlTestWordAlign // // Description: errlTestWordAlign // // End Function Specification uint32_t errlTestWordAlign() { uint32_t l_rc = 0; uint16_t l_entrySizeBefore = 0; uint16_t l_entrySizeAfter = 0; ERRL_DBG("START"); do { /****************************************************/ // Test word align for addUsrDtlsToErrl // Create log errlHndl_t l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x1, 0x2); CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); // l_handle will set to NULL after calling the commitErrl, so we need to store it errlHndl_t l_handleX = l_handle; ppdumpslot(); // add 13 bytes of "user details" l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; memset( G_data, 0xAA, sizeof( G_data ) ); addUsrDtlsToErrl( l_handle, G_data, 13, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; ERRL_DBG("Slots after create + 13 bytes" ); ppdumpslot(); // (header + WORDALIGN(13)) is the size that add to entry CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+16), l_rc); /****************************************************/ // Test word align for addTraceToErrl // add 21 bytes of trace l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; addTraceToErrl(g_trac_inf, 21, l_handle); // @at012c l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; ERRL_DBG("Slots after create + 21 bytes" ); ppdumpslot(); // (header + WORDALIGN(21)) is the size that add to entry CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+24), l_rc); commitErrl( &l_handle ); deleteErrl(&l_handleX); ERRL_DBG("Slots should now be empty"); ppdumpslot(); ERRL_DBG("END \n"); }while(0); return l_rc; }
bool COSE_Enveloped_decrypt(HCOSE_ENVELOPED h, HCOSE_RECIPIENT hRecip, cose_errback * perr) { COSE_Enveloped * pcose = (COSE_Enveloped *)h; COSE_RecipientInfo * pRecip = (COSE_RecipientInfo *)hRecip; bool f = false; CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(IsValidRecipientHandle(hRecip), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(pcose->m_recipientFirst != NULL, COSE_ERR_INVALID_PARAMETER); f = _COSE_Enveloped_decrypt(pcose, pRecip, NULL, 0, "Encrypt", perr); errorReturn: return f; }
bool AES_CCM_Decrypt(COSE_Enveloped * pcose, int TSize, int LSize, const byte * pbKey, size_t cbKey, const byte * pbCrypto, size_t cbCrypto, const byte * pbAuthData, size_t cbAuthData, cose_errback * perr) { mbedtls_ccm_context ctx; int cbOut; byte * rgbOut = NULL; int NSize = 15 - (LSize/8); byte rgbIV[15] = { 0 }; const cn_cbor * pIV = NULL; mbedtls_cipher_id_t cipher; #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pcose->m_message.m_allocContext; #endif mbedtls_ccm_init(&ctx); // Setup the IV/Nonce and put it into the message pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, NULL); if ((pIV == NULL) || (pIV->type!= CN_CBOR_BYTES)) { if (perr != NULL) perr->err = COSE_ERR_INVALID_PARAMETER; errorReturn: if (rgbOut != NULL) COSE_FREE(rgbOut, context); mbedtls_ccm_free(&ctx); return false; } CHECK_CONDITION(pIV->length == NSize, COSE_ERR_INVALID_PARAMETER); memcpy(rgbIV, pIV->v.str, pIV->length); // Setup and run the mbedTLS code cipher = MBEDTLS_CIPHER_ID_AES; CHECK_CONDITION(!mbedtls_ccm_setkey(&ctx, cipher, pbKey, cbKey*8), COSE_ERR_CRYPTO_FAIL); TSize /= 8; // Comes in in bits not bytes. cbOut = (int) cbCrypto - TSize; rgbOut = (byte *)COSE_CALLOC(cbOut, 1, context); CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY); CHECK_CONDITION(!mbedtls_ccm_auth_decrypt(&ctx, cbOut, rgbIV, NSize, pbAuthData, cbAuthData, pbCrypto, rgbOut, &pbCrypto[cbOut], TSize), COSE_ERR_CRYPTO_FAIL); mbedtls_ccm_free(&ctx); pcose->pbContent = rgbOut; pcose->cbContent = cbOut; return true; }
size_t FileImpl::Write(const t_byte *buf, size_t len) { if(!IsOpen()) return 0; t_ulong nwritten = 0; CHECK_CONDITION ( ::WriteFile(m_fhdl, buf, (DWORD)len, &nwritten, NULL), "FileImpl::Write " ); CHECK_CONDITION((nwritten == len), "FileImpl::Write "); return len; }
double loadGraphFile(void *graph, const char *filename, BOOL (*lineHandleFun)(void*,int,int,int)){ int fromId, toId, lineCounter = 0, count; clock_t begin, end; FILE *fp; begin = clock(); fp = fopen(filename, "r"); CHECK_CONDITION(fp != NULL, "Cannot Open Graph File!"); while(!feof(fp)){ count = fscanf(fp, "%d\t%d", &fromId, &toId); if(count != 2){ // check reading count of ids continue; } if(!lineHandleFun(graph, lineCounter, fromId, toId)){ break; } if(lineCounter % 1000000 == 0 && lineCounter != 0){ logMsg("read %d lines\n", lineCounter); } lineCounter += 1; } fclose(fp); end = clock(); return (double)(end - begin) / CLOCKS_PER_SEC; }
HCOSE_MAC0 _COSE_Mac0_Init_From_Object(cn_cbor * cbor, COSE_Mac0Message * pIn, CBOR_CONTEXT_COMMA cose_errback * perr) { COSE_Mac0Message * pobj = pIn; cn_cbor * pRecipients = NULL; // cn_cbor * tmp; cose_errback error = { COSE_ERR_NONE }; if (perr == NULL) perr = &error; if (pobj == NULL) pobj = (COSE_Mac0Message *)COSE_CALLOC(1, sizeof(COSE_Mac0Message), context); if (pobj == NULL) { perr->err = COSE_ERR_OUT_OF_MEMORY; errorReturn: if ((pIn == NULL) && (pobj != NULL)) COSE_FREE(pobj, context); return NULL; } if (!_COSE_Init_From_Object(&pobj->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) { goto errorReturn; } pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_MAC_RECIPIENTS); CHECK_CONDITION(pRecipients == NULL, COSE_ERR_INVALID_PARAMETER); return(HCOSE_MAC0)pobj; }
HCOSE_ENCRYPT _COSE_Encrypt_Init_From_Object(cn_cbor * cbor, COSE_Encrypt * pIn, CBOR_CONTEXT_COMMA cose_errback * perr) { COSE_Encrypt * pobj = pIn; cn_cbor * pRecipients = NULL; cose_errback error = { 0 }; if (perr == NULL) perr = &error; if (pobj == NULL) pobj = (COSE_Encrypt *)COSE_CALLOC(1, sizeof(COSE_Encrypt), context); if (pobj == NULL) { perr->err = COSE_ERR_OUT_OF_MEMORY; errorReturn: if ((pIn == NULL) && (pobj != NULL)) COSE_FREE(pobj, context); return NULL; } if (!_COSE_Init_From_Object(&pobj->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) { goto errorReturn; } pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_RECIPIENTS); CHECK_CONDITION(pRecipients == NULL, COSE_ERR_INVALID_PARAMETER); _COSE_InsertInList(&EncryptRoot, &pobj->m_message); return(HCOSE_ENCRYPT) pobj; }
TEST(FilePersistence, LoadRootOnly) { QString testDir = ":/FilePersistence/test/persisted"; Model::Model model; FileStore store; store.setBaseFolder(testDir); model.load(&store, "rootOnly"); TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root()); CHECK_CONDITION(root); CHECK_STR_EQUAL("BinaryNode", root->typeName() ); CHECK_STR_EQUAL("Title", root->name()->get() ); CHECK_CONDITION(root->left() == nullptr); CHECK_CONDITION(root->right() == nullptr); }