struct transaction * sortedArraysCommonElements(struct transaction *A, int ALen, struct transaction *B, int BLen) { if (!A || !B || ALen < 1 || BLen < 1) return NULL; int CLen = (ALen < BLen) ? ALen : BLen; struct transaction *C = (struct transaction *)malloc(sizeof(struct transaction) * CLen); int i = 0, j = 0, count = 0; while (i < ALen && j < BLen) { int comp = compareDates(A[i].date, B[j].date); if (comp == -1) return NULL; else if (!comp) { C[count++] = A[i]; i++; j++; } else if (comp == 1) i++; else j++; } if (count) return C; return NULL; }
struct transaction * mergeSortedArrays(struct transaction *A, int ALen, struct transaction *B, int BLen) { int index1 = 0, index2 = 0, resindex = 0, compare; date d1, d2; if (A == NULL || B == NULL) return NULL; struct transaction *result = (struct transaction *)malloc(sizeof(struct transaction)*(ALen + BLen)); while ((index1 < ALen) && (index2 < BLen)) { getDayMonthYear(A[index1].date, &d1); getDayMonthYear(B[index2].date, &d2); compare = compareDates(d1, d2); if (compare == 1) result[resindex++] = B[index2++]; else if (compare == -1) result[resindex++] = A[index1++]; else { result[resindex++] = A[index1++]; result[resindex++] = B[index2++]; } } while (index1 < ALen) result[resindex++] = A[index1++]; while (index2 < BLen) result[resindex++] = B[index2++]; return result; }
int DateTimeValidator::compare(const XMLCh* const value1 , const XMLCh* const value2 , MemoryManager* const manager) { try { XMLDateTime *pDate1 = parse(value1, manager); Janitor<XMLDateTime> jName1(pDate1); XMLDateTime *pDate2 = parse(value2, manager); Janitor<XMLDateTime> jName2(pDate2); int result = compareDates(pDate1, pDate2, true); return (result==INDETERMINATE)? -1 : result; } catch(const OutOfMemoryException&) { throw; } catch (...) // RuntimeException e { return -1; // revisit after implement compareDates() } }
/* * fetch stored key from DB, ensure it has same start/end date */ static int fetchStoredKey( CSSM_DL_DB_HANDLE dlDbHand, CT_KeyType lookupType, CSSM_KEY_PTR compareKey, const char *op, CSSM_BOOL quiet, CSSM_KEY_PTR *lookupKey) // RETURNED { CSSM_KEY_PTR lookup = cspLookUpKeyByLabel(dlDbHand.DLHandle, dlDbHand.DBHandle, &keyLabelData, lookupType); if(lookup == NULL) { printf("%s: Error looking up key in DB\n", op); return testError(quiet); } if(compareDates(&compareKey->KeyHeader.StartDate, &lookup->KeyHeader.StartDate, op, quiet)) { return 1; } *lookupKey = lookup; return 0; }
bool NoteCollection::getNotesByDate( const Glib::DateTime& date, unsigned int& first, unsigned int& last ) const { if( m_vecNotes.empty() || compareDates( date, m_vecNotes.front()->getDate() ) < 0 || compareDates( date, m_vecNotes.back()->getDate() ) > 0 ) { return false; } unsigned int left; unsigned int right; if( compareDates( date, m_vecNotes.front()->getDate() ) == 0 ) { first = 0; } else { left = 0; right = m_vecNotes.size() - 1; while( right - left > 1 ) { unsigned int mid = ( right + left ) / 2; int diffMid = compareDates( m_vecNotes[ mid ]->getDate(), date ); if( diffMid < 0 ) { left = mid; } else { right = mid; } } if( compareDates( date, m_vecNotes[ right ]->getDate() ) != 0 ) { return false; } else { first = right; } } if( compareDates( date, m_vecNotes.back()->getDate() ) == 0 ) { last = m_vecNotes.size() - 1; } else { left = 0; right = m_vecNotes.size() - 1; while( right - left > 1 ) { unsigned int mid = ( right + left ) / 2; int diffMid = compareDates( m_vecNotes[ mid ]->getDate(), date ); if( diffMid > 0 ) { right = mid; } else { left = mid; } } last = left; } return true; }
int ProcessingRestrictions::CheckApplicationDates() { int res; // 1. Get current (transaction) date AddCurTime2Hash(); DataObject dob_transDate; //NTNTNTNT res = EnvContext.getTagValue (0x9a, &dob_transDate, true); if (res != SUCCESS) { // Date is not in the hash; try to add it and retreive again AddCurTime2Hash(); res = EnvContext.getTagValue (0x9a, &dob_transDate, true); if (res != SUCCESS) return EMV_DATA_NOT_FOUND; } dateStruct transDate; if (!EmvDate2DateStruct(dob_transDate.Data, dob_transDate.len, &transDate)) return EMV_INVALID_FORMAT; // 2. Get application effective date from the hash DataObject dob_effectDate; res = EnvContext.getTagValue (0x5f25, &dob_effectDate, true); if (res == SUCCESS && dob_effectDate.len > 0) { // Application effective date exists; verify that the current date // is greater than or equal to the Application Effective date // (section 6.4.3, EMV book 3) // Convert dates to dateStruct format dateStruct effDate; if (!EmvDate2DateStruct(dob_effectDate.Data, dob_effectDate.len, &effDate)) return EMV_INVALID_FORMAT; if (compareDates (&effDate, &transDate) < 0) { // effDate > transDate // Set 'Application not yet effective' bit in TVR to '1' updateDataObject (0x95, &dob_TVR, 2, 0x20); } } // 3. Get Application Expiration Date from the hash DataObject dob_expDate; res = EnvContext.getTagValue (0x5f24, &dob_expDate, true); if (res != SUCCESS) { // Application Expiration Date is a mandatory data object. // It is missing from the hash (meaning it was not read from the card // in previous steps). // Exit transaction return EMV_MISSING_MANDATORY_DATA; } // Convert Appl Expiration date to dateStruct format dateStruct expDate; if (!EmvDate2DateStruct(dob_expDate.Data, dob_expDate.len, &expDate)) return EMV_INVALID_FORMAT; if (compareDates (&transDate, &expDate) < 0) { // transDate > expDate // Set 'Expired Application' bit in TVR to '1' updateDataObject (0x95, &dob_TVR, 2, 0x40); } return SUCCESS; }
/* * Common, flexible, error-tolerant key pair generator. */ static int genKeyPair( CSSM_CSP_HANDLE cspHand, uint32 algorithm, const char *keyAlgStr, uint32 keySizeInBits, CSSM_KEY_PTR pubKey, CSSM_KEYATTR_FLAGS pubKeyAttr, CSSM_KEYUSE pubKeyUsage, CSSM_KEY_PTR privKey, CSSM_KEYATTR_FLAGS privKeyAttr, CSSM_KEYUSE privKeyUsage, CSSM_BOOL quiet, bool setStartDate, int startDeltaDays, bool setEndDate, int endDeltaDays, CSSM_DL_DB_HANDLE *dlDbHand = NULL) // optional { CSSM_RETURN crtn; CSSM_CC_HANDLE ccHand; CSSM_DATE startDate; CSSM_DATE endDate; if(setStartDate) { setDate(startDate, startDeltaDays); } if(setEndDate) { setDate(endDate, endDeltaDays); } memset(pubKey, 0, sizeof(CSSM_KEY)); memset(privKey, 0, sizeof(CSSM_KEY)); crtn = CSSM_CSP_CreateKeyGenContext(cspHand, algorithm, keySizeInBits, NULL, // Seed NULL, // Salt setStartDate ? &startDate : NULL, setEndDate ? &endDate : NULL, NULL, // Params &ccHand); if(crtn) { printError("CSSM_CSP_CreateKeyGenContext", crtn); return testError(quiet); } if(dlDbHand) { /* add in DL/DB to context */ crtn = cspAddDlDbToContext(ccHand, dlDbHand->DLHandle, dlDbHand->DBHandle); if(crtn) { return testError(quiet); } } crtn = CSSM_GenerateKeyPair(ccHand, pubKeyUsage, pubKeyAttr, &keyLabelData, pubKey, privKeyUsage, privKeyAttr, &keyLabelData, // same labels NULL, // CredAndAclEntry privKey); if(crtn) { printError("CSSM_GenerateKeyPair", crtn); return testError(quiet); } CSSM_DeleteContext(ccHand); CSSM_KEYHEADER &pubHdr = pubKey->KeyHeader; CSSM_KEYHEADER &privHdr = privKey->KeyHeader; CSSM_DATE *cdp = NULL; if(setStartDate) { cdp = &startDate; } if(compareDates(cdp, &pubHdr.StartDate, keyAlgStr, quiet)) { return 1; } if(compareDates(cdp, &privHdr.StartDate, keyAlgStr, quiet)) { return 1; } if(setEndDate) { cdp = &endDate; } else { cdp = NULL; } if(compareDates(cdp, &pubHdr.EndDate, keyAlgStr, quiet)) { return 1; } if(compareDates(cdp, &privHdr.EndDate, keyAlgStr, quiet)) { return 1; } return 0; }