void AESTests::testWrap(const char testKeK[][128], const char testKey[][128], const char testCt[][128], const int testCnt, SymWrap::Type mode) { for (int i = 0; i < testCnt; i++) { ByteString kekData(testKeK[i]); ByteString keyData(testKey[i]); AESKey aesKeK(kekData.size() * 8); CPPUNIT_ASSERT(aesKeK.setKeyBits(kekData)); ByteString wrapped; ByteString expectedCt(testCt[i]); CPPUNIT_ASSERT(aes->wrapKey(&aesKeK, mode, keyData, wrapped)); CPPUNIT_ASSERT(wrapped.size() == expectedCt.size()); CPPUNIT_ASSERT(wrapped == expectedCt); ByteString unwrapped; CPPUNIT_ASSERT(aes->unwrapKey(&aesKeK, mode, wrapped, unwrapped)); CPPUNIT_ASSERT(unwrapped.size() == keyData.size()); CPPUNIT_ASSERT(unwrapped == keyData); /* #ifdef HAVE_AES_KEY_WRAP_PAD keyData.resize(20); ByteString padwrapped; CPPUNIT_ASSERT(aes->wrapKey(&aesKeK, SymWrap::AES_KEYWRAP_PAD, keyData, padwrapped)); CPPUNIT_ASSERT(padwrapped.size() == 32); ByteString padunwrapped; CPPUNIT_ASSERT(aes->unwrapKey(&aesKeK, SymWrap::AES_KEYWRAP_PAD, padwrapped, padunwrapped)); CPPUNIT_ASSERT(padunwrapped == keyData); #endif */ } }
QString XSLTransformer::transform(const QString &xml, QHash<QString, QString> const ¶ms) const { // Read XML data intro an xmlDoc. QByteArray xmlData(xml.toUtf8()); QScopedPointer<xmlDoc, XmlDocDeleter> doc( xmlReadMemory(xmlData.constData(), xmlData.size(), 0, 0, 0)); if (!doc) throw std::runtime_error("XSLTransformer::transform: Could not open XML data"); // Hmpf, data conversions. char const **cParams = new char const *[params.size() * 2 + 1]; int i = 0; for (QHash<QString, QString>::const_iterator iter = params.constBegin(); iter != params.constEnd(); ++iter) { QByteArray keyData(iter.key().toUtf8()); QByteArray valueData(iter.value().toUtf8()); char const *cKey = strdup(keyData.constData()); char const *cValue = strdup(valueData.constData()); cParams[i] = cKey; cParams[i + 1] = cValue; i += 2; } cParams[params.size() * 2] = 0; // Terminator QScopedPointer<xsltTransformContext, XsltTransformContextDeleter> ctx( xsltNewTransformContext(d_xslPtr.data(), doc.data())); xsltSetCtxtParseOptions(ctx.data(), XSLT_PARSE_OPTIONS); // Transform... QScopedPointer<xmlDoc, XmlDocDeleter> res( xsltApplyStylesheetUser(d_xslPtr.data(), doc.data(), cParams, NULL, NULL, ctx.data())); if (!res) throw std::runtime_error("XSLTransformer::transform: Could not apply transformation!"); else if (ctx->state != XSLT_STATE_OK) throw std::runtime_error("XSLTransformer::transform: Transformation error, check your query!"); xmlChar *outputBare = 0; int outputLen = -1; xsltSaveResultToString(&outputBare, &outputLen, res.data(), d_xslPtr.data()); QScopedPointer<xmlChar, XmlDeleter> output(outputBare); if (!output) throw std::runtime_error("Could not apply stylesheet!"); QString result(QString::fromUtf8(reinterpret_cast<char const *>(output.data()))); // Deallocate parameter memory for (int i = 0; i < params.size() * 2; ++i) free(const_cast<char *>(cParams[i])); delete[] cParams; return result; }
void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, IDBKey* key, SerializedScriptValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode) { RefPtr<InProcessIDBServer> self(this); IDBKeyData keyData(key); auto valueData = ThreadSafeDataBuffer::copyVector(value.data()); RunLoop::current().dispatch([this, self, requestData, keyData, valueData, overwriteMode] { m_server->putOrAdd(requestData, keyData, valueData, overwriteMode); }); }
std::string queryValueString( const char *name, DWORD keyType = REG_SZ ) { DWORD keyDataLength = 0; DWORD keyTypeParam = keyType; // One call to get the size RegQueryValueEx( this->_hKey, name, NULL, &keyTypeParam, NULL, &keyDataLength ); spep::CArray<char> keyData( keyDataLength + 1 ); keyTypeParam = keyType; // One call to get the value RegQueryValueEx( this->_hKey, name, NULL, &keyTypeParam, reinterpret_cast<PBYTE>(keyData.get()), &keyDataLength ); keyData[ keyDataLength ] = '\0'; return std::string( keyData.get(), keyDataLength ); }
void ccHistogramWindow::refreshBars() { if ( m_histogram && m_colorScheme == USE_SF_SCALE && m_associatedSF && m_associatedSF->getColorScale()) { int histoSize = static_cast<int>(m_histoValues.size()); //DGM: the bars will be redrawn only if we delete and recreate the graph?! m_histogram->clearData(); QVector<double> keyData(histoSize); QVector<double> valueData(histoSize); QVector<QColor> colors(histoSize); for (int i=0; i<histoSize; ++i) { //we take the 'normalized' value at the middle of the class double normVal = (static_cast<double>(i)+0.5) / histoSize; keyData[i] = m_minVal + normVal * (m_maxVal - m_minVal); valueData[i] = m_histoValues[i]; const ColorCompType* col= m_associatedSF->getColor(static_cast<ScalarType>(keyData[i])); if (!col) //hidden values may have no associated color! col = ccColor::lightGrey.rgba; colors[i] = QColor(col[0],col[1],col[2]); } m_histogram->setData(keyData, valueData, colors); //rescaleAxes(); } replot(QCustomPlot::rpImmediate); }
void ccHistogramWindow::refresh() { // set ranges appropriate to show data double minVal = m_minVal; double maxVal = m_maxVal; if (m_sfInteractionMode && m_associatedSF) { double minSat = m_associatedSF->saturationRange().min(); double maxSat = m_associatedSF->saturationRange().max(); minVal = std::min(minVal,minSat); maxVal = std::max(maxVal,maxSat); } xAxis->setRange(minVal, maxVal); yAxis->setRange(0, m_maxHistoVal); if (!m_titleStr.isEmpty()) { // add title layout element if (!m_titlePlot) { //add a row for the title plotLayout()->insertRow(0); } else { //remove previous title plotLayout()->remove(m_titlePlot); m_titlePlot = 0; } m_titlePlot = new QCPPlotTitle(this, QString("%0 [%1 classes]").arg(m_titleStr).arg(m_histoValues.size())); //title font m_renderingFont.setPointSize(ccGui::Parameters().defaultFontSize); m_titlePlot->setFont(m_renderingFont); plotLayout()->addElement(0, 0, m_titlePlot); } //clear previous display m_histogram = 0; m_vertBar = 0; m_overlayCurve = 0; m_areaLeft = 0; m_areaRight = 0; m_arrowLeft = 0; m_arrowRight = 0; this->clearGraphs(); this->clearPlottables(); if (m_histoValues.empty()) return; //default color scale to be used for display ccColorScale::Shared colorScale = (m_colorScale ? m_colorScale : ccColorScalesManager::GetDefaultScale()); //histogram int histoSize = static_cast<int>(m_histoValues.size()); double totalSum = 0; double partialSum = 0; if (histoSize > 0) { m_histogram = new QCPColoredBars(xAxis, yAxis); addPlottable(m_histogram); // now we can modify properties of myBars: m_histogram->setWidth((m_maxVal - m_minVal) / histoSize); m_histogram->setAntialiasedFill(false); QVector<double> keyData(histoSize); QVector<double> valueData(histoSize); HISTOGRAM_COLOR_SCHEME colorScheme = m_colorScheme; switch(colorScheme) { case USE_SOLID_COLOR: m_histogram->setBrush(QBrush(m_solidColor,Qt::SolidPattern)); m_histogram->setPen(QPen(m_solidColor)); break; case USE_CUSTOM_COLOR_SCALE: //nothing to do break; case USE_SF_SCALE: if (m_associatedSF && m_associatedSF->getColorScale()) { //we use the SF's color scale colorScale = m_associatedSF->getColorScale(); } else { //we'll use the default one... assert(false); colorScheme = USE_CUSTOM_COLOR_SCALE; } break; default: assert(false); colorScheme = USE_CUSTOM_COLOR_SCALE; break; } QVector<QColor> colors; if (colorScheme != USE_SOLID_COLOR) { colors.resize(histoSize); } for (int i=0; i<histoSize; ++i) { //we take the 'normalized' value at the middle of the class double normVal = (static_cast<double>(i)+0.5) / histoSize; totalSum += m_histoValues[i]; if (normVal < m_verticalIndicatorPositionPercent) partialSum += m_histoValues[i]; keyData[i] = m_minVal + normVal * (m_maxVal - m_minVal); valueData[i] = m_histoValues[i]; //import color for the current bin if (colorScheme != USE_SOLID_COLOR) { const ColorCompType* col = 0; if (colorScheme == USE_SF_SCALE) { //equivalent SF value assert(m_associatedSF); col = m_associatedSF->getColor(static_cast<ScalarType>(keyData[i])); } else if (colorScheme == USE_CUSTOM_COLOR_SCALE) { //use default gradient assert(colorScale); col = colorScale->getColorByRelativePos(normVal); } if (!col) //hidden values may have no associated color! col = ccColor::lightGrey.rgba; colors[i] = QColor(col[0],col[1],col[2]); } } if (!colors.isEmpty()) m_histogram->setData(keyData, valueData, colors); else m_histogram->setData(keyData, valueData); } //overlay curve? int curveSize = static_cast<int>(m_curveValues.size()); if (curveSize > 1) { QVector<double> x(curveSize), y(curveSize); double step = (m_maxVal - m_minVal) / (curveSize-1); for (int i=0; i<curveSize; ++i) { x[i] = m_minVal + (static_cast<double>(i)/*+0.5*/) * step; y[i] = m_curveValues[i]; } // create graph and assign data to it: m_overlayCurve = addGraph(); m_overlayCurve->setData(x, y); m_overlayCurve->setName("OverlayCurve"); //set pen color const ccColor::Rgba& col = ccColor::darkGrey; QPen pen(QColor(col.r,col.g,col.b)); m_overlayCurve->setPen(pen); //set width updateOverlayCurveWidth(rect().width(),rect().height()); } //sf interaction mode if (m_sfInteractionMode && m_associatedSF) { const ccScalarField::Range& dispRange = m_associatedSF->displayRange(); m_areaLeft = new QCPHiddenArea(true,xAxis, yAxis); m_areaLeft->setRange(dispRange.min(),dispRange.max()); m_areaLeft->setCurrentVal(dispRange.start()); addPlottable(m_areaLeft); m_areaRight = new QCPHiddenArea(false,xAxis, yAxis); m_areaRight->setRange(dispRange.min(),dispRange.max()); m_areaRight->setCurrentVal(dispRange.stop()); addPlottable(m_areaRight); const ccScalarField::Range& satRange = m_associatedSF->saturationRange(); m_arrowLeft = new QCPArrow(xAxis, yAxis); m_arrowLeft->setRange(satRange.min(),satRange.max()); m_arrowLeft->setCurrentVal(satRange.start()); if (colorScale) { const ColorCompType* col = colorScale->getColorByRelativePos(m_associatedSF->symmetricalScale() ? 0.5 : 0,m_associatedSF->getColorRampSteps()); if (col) m_arrowLeft->setColor(col[0],col[1],col[2]); } addPlottable(m_arrowLeft); m_arrowRight = new QCPArrow(xAxis, yAxis); m_arrowRight->setRange(satRange.min(),satRange.max()); m_arrowRight->setCurrentVal(satRange.stop()); if (colorScale) { const ColorCompType* col = colorScale->getColorByRelativePos(1.0,m_associatedSF->getColorRampSteps()); if (col) m_arrowRight->setColor(col[0],col[1],col[2]); } addPlottable(m_arrowRight); } else if (m_drawVerticalIndicator) //vertical hint { m_vertBar = new QCPBarsWithText(xAxis, yAxis); addPlottable(m_vertBar); // now we can modify properties of vertBar m_vertBar->setName("VertLine"); m_vertBar->setWidth(0/*(m_maxVal - m_minVal) / histoSize*/); m_vertBar->setBrush(QBrush(Qt::red)); m_vertBar->setPen(QPen(Qt::red)); m_vertBar->setAntialiasedFill(false); QVector<double> keyData(1); QVector<double> valueData(1); //horizontal position keyData[0] = m_minVal + (m_maxVal-m_minVal) * m_verticalIndicatorPositionPercent; valueData[0] = m_maxHistoVal; m_vertBar->setData(keyData,valueData); //precision (same as color scale) int precision = static_cast<int>(ccGui::Parameters().displayedNumPrecision); unsigned bin = static_cast<unsigned>(m_verticalIndicatorPositionPercent * m_histoValues.size()); QString valueStr = QString("bin %0").arg(bin); m_vertBar->setText(valueStr); valueStr = QString("< %0 %").arg(100.0*static_cast<double>(partialSum)/static_cast<double>(totalSum),0,'f',3); m_vertBar->appendText(valueStr); valueStr = QString("val = %0").arg(m_minVal+(m_maxVal-m_minVal)*m_verticalIndicatorPositionPercent,0,'f',precision); m_vertBar->appendText(valueStr); m_vertBar->setTextAlignment(m_verticalIndicatorPositionPercent > 0.5); } //rescaleAxes(); // redraw replot(); }
/* * Obtain a CSSM_KEY from a CSSM_X509_SUBJECT_PUBLIC_KEY_INFO, * inferring as much as we can from required fields * (CSSM_X509_SUBJECT_PUBLIC_KEY_INFO) and extensions (for * KeyUse, obtained from the optional DecodedCert). */ CSSM_KEY_PTR CL_extractCSSMKeyNSS( const CSSM_X509_SUBJECT_PUBLIC_KEY_INFO &keyInfo, Allocator &alloc, const DecodedCert *decodedCert) // optional { CSSM_KEY_PTR cssmKey = (CSSM_KEY_PTR) alloc.malloc(sizeof(CSSM_KEY)); memset(cssmKey, 0, sizeof(CSSM_KEY)); CSSM_KEYHEADER &hdr = cssmKey->KeyHeader; CssmRemoteData keyData(alloc, cssmKey->KeyData); hdr.HeaderVersion = CSSM_KEYHEADER_VERSION; /* CspId blank */ hdr.BlobType = CSSM_KEYBLOB_RAW; hdr.AlgorithmId = CL_oidToAlg(keyInfo.algorithm.algorithm); hdr.KeyAttr = CSSM_KEYATTR_MODIFIABLE | CSSM_KEYATTR_EXTRACTABLE; /* * Format inferred from AlgorithmId. I have never seen these defined * anywhere, e.g., what's the format of an RSA public key in a cert? * X509 certainly doesn't say. However. the following two cases are * known to be correct. */ switch(hdr.AlgorithmId) { case CSSM_ALGID_RSA: hdr.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS1; break; case CSSM_ALGID_DSA: case CSSM_ALGID_ECDSA: case CSSM_ALGID_DH: case CSSM_ALGMODE_PKCS1_EME_OAEP: hdr.Format = CSSM_KEYBLOB_RAW_FORMAT_X509; break; case CSSM_ALGID_FEE: /* CSSM_KEYBLOB_RAW_FORMAT_NONE --> DER encoded */ hdr.Format = CSSM_KEYBLOB_RAW_FORMAT_NONE; break; default: /* punt */ hdr.Format = CSSM_KEYBLOB_RAW_FORMAT_NONE; } hdr.KeyClass = CSSM_KEYCLASS_PUBLIC_KEY; /* KeyUsage inferred from extensions */ if(decodedCert) { hdr.KeyUsage = decodedCert->inferKeyUsage(); } else { hdr.KeyUsage = CSSM_KEYUSE_ANY; } /* start/end date unknown, leave zero */ hdr.WrapAlgorithmId = CSSM_ALGID_NONE; hdr.WrapMode = CSSM_ALGMODE_NONE; switch(hdr.AlgorithmId) { case CSSM_ALGID_DSA: case CSSM_ALGID_ECDSA: case CSSM_ALGID_DH: case CSSM_ALGMODE_PKCS1_EME_OAEP: { /* * Just encode the whole subject public key info blob. * NOTE we're assuming that the keyInfo.subjectPublicKey * field is in the NSS_native BITSTRING format, i.e., * its Length field is in bits and we don't have to adjust. */ PRErrorCode prtn = SecNssEncodeItemOdata(&keyInfo, kSecAsn1SubjectPublicKeyInfoTemplate, keyData); if(prtn) { clErrorLog("extractCSSMKey: error on reencode\n"); CssmError::throwMe(CSSMERR_CL_MEMORY_ERROR); } break; } default: /* * RSA, FEE for now. * keyInfo.subjectPublicKey (in BITS) ==> KeyData */ keyData.copy(keyInfo.subjectPublicKey.Data, (keyInfo.subjectPublicKey.Length + 7) / 8); } /* * LogicalKeySizeInBits - ask the CSP */ CSSM_CSP_HANDLE cspHand = getGlobalCspHand(true); CSSM_KEY_SIZE keySize; CSSM_RETURN crtn; crtn = CSSM_QueryKeySizeInBits(cspHand, CSSM_INVALID_HANDLE, cssmKey, &keySize); switch(crtn) { default: CssmError::throwMe(crtn); case CSSMERR_CSP_APPLE_PUBLIC_KEY_INCOMPLETE: /* * This is how the CSP indicates a "partial" public key, * with a valid public key value but no alg-specific * parameters (currently, DSA only). */ hdr.KeyAttr |= CSSM_KEYATTR_PARTIAL; /* and drop thru */ case CSSM_OK: cssmKey->KeyHeader.LogicalKeySizeInBits = keySize.LogicalKeySizeInBits; break; } keyData.release(); return cssmKey; }