static int p12MacParse(
	const NSS_P12_MacData &macData, 
	P12ParseInfo &pinfo,
	unsigned depth)		// print indent depth
{
	if(p12AlgIdParse(macData.mac.digestAlgorithm, NULL, pinfo, depth)) {
		return 1;
	}
	doIndent(depth);
	printf("Digest : ");
	printDataAsHex(&macData.mac.digest, 20);
	doIndent(depth);
	printf("Salt : ");
	printDataAsHex(&macData.macSalt, 16);
	const CSSM_DATA &iter = macData.iterations;
	
	if(iter.Length > 4) {
		doIndent(depth);
		printf("***Warning: malformed iteraton length (%u)\n",
			(unsigned)iter.Length);
	}
	unsigned i = dataToInt(iter);
	doIndent(depth);
	printf("Iterations = %u\n", i);
	return 0;
}
/*
 * Parse an encoded NSS_P12_AuthenticatedSafe
 */
static int authSafeParse(
	const CSSM_DATA authSafeBlob,
	P12ParseInfo &pinfo,
	unsigned depth)		// print indent depth
{
	NSS_P12_AuthenticatedSafe authSafe;
	
	memset(&authSafe, 0, sizeof(authSafe));
	if(pinfo.mCoder.decodeItem(authSafeBlob,
			NSS_P12_AuthenticatedSafeTemplate,
			&authSafe)) {
		printf("***Error decoding authSafe\n");
		return 1;
	}
	unsigned numInfos = nssArraySize((const void **)authSafe.info);
	doIndent(depth);
	printf("authSafe numInfos %u\n", numInfos);
	
	int rtn = 0;
	for(unsigned dex=0; dex<numInfos; dex++) {
		NSS_P7_DecodedContentInfo *info = authSafe.info[dex];
		doIndent(depth);
		printf("AuthSafe.info[%u] {\n", dex);
		rtn = authSafeElementParse(info, pinfo, depth+3);
		if(rtn) {
			break;
		}
		doIndent(depth);
		printf("}\n");
	}
	return rtn;
}
/*
 * Parse a NSS_P7_EncryptedData - specifically in the context
 * of a P12 in password privacy mode. (The latter assumption is
 * to enable us to infer CSSM_X509_ALGORITHM_IDENTIFIER.parameters
 * format). 
 */
static int encryptedDataParse(
	const NSS_P7_EncryptedData &edata,
	P12ParseInfo &pinfo,
	NSS_P12_PBE_Params *pbep,		// optional, RETURNED
	unsigned depth)					// print indent depth
{
	doIndent(depth);
	printf("version = %u\n", (unsigned)dataToInt(edata.version));
	const NSS_P7_EncrContentInfo &ci = edata.contentInfo;
	doIndent(depth);
	printf("contentType = %s\n", oidStr(ci.contentType, pinfo.mParser));
	
	/*
	 * Parse the alg ID, safe PBE params for when we do the 
	 * key unwrap
	 */
	const CSSM_X509_ALGORITHM_IDENTIFIER &algId = ci.encrAlg;
	if(p12AlgIdParse(algId, pbep, pinfo, depth)) {
		return 1;
	}
	
	doIndent(depth);
	printf("encrContent : ");
	printDataAsHex(&ci.encrContent, 12);
	return 0;
}
static int p12Parse(
	const CSSM_DATA &rawBlob, 
	P12ParseInfo &pinfo,
	unsigned depth)		// print indent depth
{
	NSS_P12_DecodedPFX pfx;
	memset(&pfx, 0, sizeof(pfx));
	if(pinfo.mCoder.decodeItem(rawBlob, NSS_P12_DecodedPFXTemplate, &pfx)) {
		printf("***Error on top-level decode of NSS_P12_DecodedPFX\n");
		return 1;
	}
	doIndent(depth);
	printf("version = %u\n", (unsigned)dataToInt(pfx.version));
	NSS_P7_DecodedContentInfo &dci = pfx.authSafe;

	doIndent(depth);
	printf("contentType = %s\n", oidStr(dci.contentType, pinfo.mParser));
	doIndent(depth);
	printf("type = %s\n", p7ContentInfoTypeStr(dci.type));
	int rtn = 0;
	if(nssCompareCssmData(&dci.contentType, &CSSMOID_PKCS7_Data)) {
		doIndent(depth);
		printf("AuthenticatedSafe Length %u {\n", 
			(unsigned)dci.content.data->Length);
		rtn = authSafeParse(*dci.content.data, pinfo, depth+3);
		doIndent(depth);
		printf("}\n");
	}
	else {
		printf("Not parsing any other content type today.\n");
	}
	if(pfx.macData) {
		doIndent(depth);
		printf("Mac Data {\n");
		p12MacParse(*pfx.macData, pinfo, depth+3);
		doIndent(depth);
		printf("}\n");
		if(pinfo.mPwd.Data == NULL) {
			doIndent(depth);
			printf("=== MAC not verified (no passphrase)===\n");
		}
		else {
			CSSM_RETURN crtn = p12VerifyMac_app(pfx, pinfo.mCspHand, 
				pinfo.mPwd, pinfo.mCoder);
			doIndent(depth);
			if(crtn) {
				cssmPerror("p12VerifyMac", crtn);
				doIndent(depth);
				printf("***MAC verify failure.\n");
			}
			else {
				printf("MAC verifies OK.\n");
			}
		}
	}
	return 0;
}
static void printCritical(
	int indent,
	OCSPExtension *ocspExt)
{
	doIndent(indent);
	printf("Critical           : %s\n", ocspExt->critical() ? "true" : "false");
}
Пример #6
0
void OutputVisitor::visit(const MarkupNode& node)
{
	doIndent();

	writeMarkupOpening(node);
	_out << CLOSING_MARKUP_STR << CLOSE_MARKUP_STR << endl;
}
Пример #7
0
bool KateAutoIndent::doIndentRelative(int line, int change)
{
  kDebug (13060) << "doIndentRelative: line: " << line << " change: " << change;

  Kate::TextLine textline = doc->plainKateTextLine(line);

  // get indent width of current line
  int indentDepth = textline->indentDepth (tabWidth);
  int extraSpaces = indentDepth % indentWidth;

  // add change
  indentDepth += change;

  // if keepExtra is off, snap to a multiple of the indentWidth
  if (!keepExtra && extraSpaces > 0)
  {
    if (change < 0)
      indentDepth += indentWidth - extraSpaces;
    else
      indentDepth -= extraSpaces;
  }

  // do indent
  return doIndent(line, indentDepth);
}
Пример #8
0
void KateAutoIndent::scriptIndent (KateView *view, const KTextEditor::Cursor &position, QChar typedChar)
{
  QPair<int, int> result = m_script->indent (view, position, typedChar, indentWidth);
  int newIndentInChars = result.first;

  // handle negative values special
  if (newIndentInChars < -1)
    return;

  // reuse indentation of the previous line, just like the "normal" indenter
  if (newIndentInChars == -1)
  {
    // keep indent of previous line
    keepIndent (position.line());

    return;
  }

  int align = result.second;
  if (align > 0)
    kDebug (13060) << "Align: " << align;

  // we got a positive or zero indent to use...
  doIndent (position.line(), newIndentInChars, align);
}
Пример #9
0
 void beginCatch() override {
   end();
   indent--;
   doIndent();
   out.append("} .catch {\n");
   indent++;
 }
Пример #10
0
  void endRegion() override {
    end();
    indent--;
    doIndent();
    out.append("}\n");

  }
static int attrParse(
	const NSS_Attribute *attr,
	P12ParseInfo &pinfo, 
	unsigned depth)
{
	doIndent(depth);
	printf("attrType : %s\n", oidStr(attr->attrType, pinfo.mParser));
	unsigned numVals = nssArraySize((const void **)attr->attrValue);
	doIndent(depth);
	printf("numValues = %u\n", numVals);

	for(unsigned dex=0; dex<numVals; dex++) {
		doIndent(depth);
		printf("val[%u] : ", dex);
		
		/*
		 * Note: these two enumerated types should only have one att value 
		 * per PKCS9. Leave that to real apps, we want to see what's there
		 * in any case.
		 */
		if(nssCompareCssmData(&attr->attrType, &CSSMOID_PKCS9_FriendlyName)) {
			/* BMP string (UniCode) */
			CSSM_DATA ustr;
			if(pinfo.mCoder.decodeItem(*attr->attrValue[dex],
					kSecAsn1BMPStringTemplate, &ustr)) {
				printf("***Error decoding BMP string\n");
				continue;
			}
			printDataAsUnichars(ustr);
		}
		else if(nssCompareCssmData(&attr->attrType, 
					&CSSMOID_PKCS9_LocalKeyId)) {
			/* Octet string */
			CSSM_DATA ostr;
			if(pinfo.mCoder.decodeItem(*attr->attrValue[dex],
					kSecAsn1ObjectIDTemplate, &ostr)) {
				printf("***Error decoding LocalKeyId string\n");
				continue;
			}
			printDataAsHex(&ostr, 16);
		}
		else {
			printDataAsHex(attr->attrValue[dex], 8);
		}
	}
	return 0;
}
Пример #12
0
/**
 * Put a double value.
 * @param val	Value to put.
 */
void Saver::put(double val) throw(io::IOException) {
	ASSERTP(state == FIELD || isArray(state), "json: cannot put a value out of a field or an array!");
	doIndent();
	_out << val;
	if(state == FIELD)
		state = stack.pop();
	state = next(state);
}
Пример #13
0
/**
 * End an array. Only allowed inside an array.
 */
void Saver::endArray(void) throw(io::IOException) {
	ASSERTP(isArray(state), "json: not inside an array!");
	state_t new_state = next(stack.pop());
	state = ARRAY;
	doIndent(true);
	_out << "]";
	state = new_state;
}
Пример #14
0
/**
 * Begin an array. Only allowed inside an array or in a field.
 */
void Saver::beginArray(void) throw(io::IOException) {
	ASSERTP(state != END, "json: ended output!");
	ASSERTP(state == FIELD || isArray(state), "json: array only allowed in a field or in an array");
	doIndent();
	_out << "[";
	if(state != FIELD)
		stack.push(state);
	state = ARRAY;
}
Пример #15
0
/**
 * End an object. Only allowed inside an object.
 */
void Saver::endObject(void) throw(io::IOException) {
	ASSERTP(isObject(state), "json: not inside an object!");
	if(!stack)
		state = END;
	else
		state = next(stack.pop());
	doIndent(true);
	_out << "}";
}
Пример #16
0
/**
 * Begin an object. Only allowed at the beginning of the output,
 * after adding an object or inside an array.
 */
void Saver::beginObject(void) throw(io::IOException) {
	ASSERTP(state != END, "json: ended output!");
	ASSERTP(!isObject(state), "json: object creation only allowed in a field or an array");
	doIndent();
	_out << "{";
	if(isArray(state))
		stack.push(state);
	state = OBJECT;
}
/*
 * Parse an CSSM_X509_ALGORITHM_IDENTIFIER specific to P12.
 * Decode the alg params as a NSS_P12_PBE_Params and parse and 
 * return the result if the pbeParams is non-NULL.
 */
static int p12AlgIdParse(
	const CSSM_X509_ALGORITHM_IDENTIFIER &algId,
	NSS_P12_PBE_Params *pbeParams,		// optional
	P12ParseInfo &pinfo,
	unsigned depth)						// print indent depth
{
	doIndent(depth);
	printf("encrAlg = %s\n", oidStr(algId.algorithm, pinfo.mParser));
	const CSSM_DATA &param = algId.parameters;
	if(pbeParams == NULL) {
		/* alg params are uninterpreted */
		doIndent(depth);
		printf("Alg Params : ");
		printDataAsHex(&param);
		return 0;
	}
	
	if(param.Length == 0) {
		printf("===warning: no alg parameters, this is not optional\n");
		return 0;
	}
	
	memset(pbeParams, 0, sizeof(*pbeParams));
	if(pinfo.mCoder.decodeItem(param, 
			NSS_P12_PBE_ParamsTemplate, pbeParams)) {
		printf("***Error decoding NSS_P12_PBE_Params\n");
		return 1;
	}
	doIndent(depth);
	printf("Salt : ");
	printDataAsHex(&pbeParams->salt);
	doIndent(depth);
	if(pbeParams->iterations.Length > 4) {
		printf("warning: iterations greater than max int\n");
		doIndent(depth);
		printf("Iterations : ");
		printDataAsHex(&pbeParams->iterations);
	}
	else {
		printf("Iterations : %u\n", 
			(unsigned)dataToInt(pbeParams->iterations));
	}
	return 0;
}
Пример #18
0
 void label(Block* blk) {
   // if there was an unconditional jump and its target was *not* this block
   // actually emit the instruction
   if (nextUnconditionalDestination
       && nextUnconditionalDestination != blk) {
     dump(bc::Jmp{nextUnconditionalDestination});
   }
   nextUnconditionalDestination = nullptr;
   doIndent();
   folly::format(&out, "L{}:\n", blk->id);
 }
Пример #19
0
/**
 * Put a string value.
 * @param val	String to put.
 */
void Saver::put(string val) throw(io::IOException) {
	ASSERTP(state == FIELD || isArray(state), "json: cannot put a value out of a field or an array!");
	doIndent();
	_out << '"';
	for(utf8::Iter i(val); i; i++)
		escape(*i);
	_out << '"';
	if(state == FIELD)
		state = stack.pop();
	state = next(state);
}
Пример #20
0
/**
 * Put a boolean value.
 * @param val	Value to put.
 */
void Saver::put(bool val) throw(io::IOException) {
	ASSERTP(state == FIELD || isArray(state), "json: cannot put a value out of a field or an array!");
	doIndent();
	if(val)
		_out << "true";
	else
		_out << "false";
	if(state == FIELD)
		state = stack.pop();
	state = next(state);
}
static void dumpCertID(
	SecAsn1OCSPCertID *certID,
	int indent)
{
	doIndent(indent);
	printf("algId            : ");
	printDataAsHex(&certID->algId.algorithm);
	
	doIndent(indent);
	printf("issuerNameHash   : ");
	printDataAsHex(&certID->issuerNameHash);
	
	doIndent(indent);
	printf("issuerPubKeyHash : ");
	printDataAsHex(&certID->issuerPubKeyHash);
	
	doIndent(indent);
	printf("serialNumber     : ");
	printDataAsHex(&certID->serialNumber);
}
Пример #22
0
 /** @brief Prints to the log file. */
 void print(const char *format, ...)
 {
   if(open()) {
     doIndent();
     va_list args;
     va_start(args, format);
     vfprintf(gLogFP, format, args);
     fputc('\n', gLogFP);
     fflush(gLogFP);
     va_end(args);
   }  
 }
/*
 * CrlBag parser
 */
static int crlBagParse(
	const NSS_P12_CrlBag *crlBag,
	P12ParseInfo &pinfo,
	unsigned depth)
{
	/* fixe - we really need to store the attrs along with the crl here! */
	switch(crlBag->type) {
		case CRT_X509:
			doIndent(depth);
			printf("X509 CRL found, size %u\n", 
				(unsigned)crlBag->crlValue.Length);
			pinfo.mParsed.mCrls.addBlob(crlBag->crlValue);
			break;
		default:
			doIndent(depth);
			printf("Unknown CRL type found\n");
			P12UnknownBlob *uk = new P12UnknownBlob(crlBag->crlValue,
				crlBag->bagType);
			pinfo.mParsed.mUnknown.addBlob(uk);
	}
	return 0;
}
Пример #24
0
qString qDeclare::print( int indent )
{
	qString ret = doIndent(indent) + printType(neu_type) + " $" + name;
	
	if (size())
	{
		ret += " = " + L()->print(0);
	}

	if (indent)
		ret += ";";

	return ret;
}
Пример #25
0
    /** @brief Prints to the log file only if the condition is true and prepends an error notice. */
    void error(bool condition, const char *format, ...)
    {
      if(condition && open()) {
        doIndent();
        fputs("ERROR : ", gLogFP);

        va_list args;
        va_start(args, format);
        vfprintf(gLogFP, format, args);
        fputc('\n', gLogFP);
        va_end(args);

        fflush(gLogFP);
      }  
    }
Пример #26
0
void OutputVisitor::visit(const CompositeMarkupNode& node)
{
	doIndent();

	writeMarkupOpening(node);
	_out << CLOSE_MARKUP_STR << endl;

	_indent += _indentUnit;
	int count = 0;
	for (CompositeMarkupNode::ChildrenIterator it = node.begin(); it
			!= node.end(); ++it)
	{
		(*it)->accept(*this);
	}
	_indent -= _indentUnit;

	doIndent();
	_out << OPEN_MARKUP_STR << CLOSING_MARKUP_STR;
	if (!node.ns().empty())
	{
		_out << node.ns() << NS_SEPARATOR_STR;
	}
	_out << node.name() << CLOSE_MARKUP_STR << endl;
}
Пример #27
0
/*
 * Print line header, with current indent, followed by specified label, followed
 * by a ':' in column COLON_COLUMN, followed by one space. 
 */
void printHeader(
	const char *label)
{
	size_t numPrinted;
	
	doIndent();
	printf("%s", label);
	numPrinted = indentLevel + strlen(label);
	if(numPrinted < COLON_COLUMN) {
		size_t numSpaces = COLON_COLUMN - numPrinted;
		size_t dex;
		for(dex=0; dex<numSpaces; dex++) {
			putchar(' ');
		}
	}
	printf(": ");
}
Пример #28
0
/* 
 * This is a SEQUENCE OF so we use the low-level DERDecodeSeq* routines to snag one entry 
 * at a time.
 */
static void	printRevokedCerts(
	DERItem *revokedCerts, 
	int verbose)
{
	DERReturn drtn;
	DERDecodedInfo currItem;
	DERSequence seq;
	unsigned certNum;
	DERRevokedCert revoked;
	
	drtn = DERDecodeSeqContentInit(revokedCerts, &seq);
	if(drtn) {
		DERPerror("DERDecodeSeqContentInit(revokedCerts)", drtn);
		return;
	}
	
	for(certNum=0; ; certNum++) {
		drtn = DERDecodeSeqNext(&seq, &currItem);
		switch(drtn) {
			case DR_EndOfSequence:
				/* normal termination */
				return;
			default:
				DERPerror("DERDecodeSeqNext", drtn);
				return;
			case DR_Success:
				doIndent();
				printf("revoked cert %u\n", certNum);
				incrIndent();
				drtn = DERParseSequenceContent(&currItem.content, 
					DERNumRevokedCertItemSpecs, DERRevokedCertItemSpecs,
					&revoked, sizeof(revoked));
				if(drtn) {
					DERPerror("DERParseSequenceContent(RevokedCert)", drtn);
					decrIndent();
					return;
				}
				printItem("serialNum", IT_Leaf, verbose, ASN1_INTEGER, &revoked.serialNum);
				decodePrintItem("revocationDate",  IT_Leaf, verbose, &revoked.revocationDate);
				printItem("extensions", IT_Branch, verbose, ASN1_CONSTR_SEQUENCE, &revoked.extensions);
				decrIndent();
		}
	}
}
Пример #29
0
 void block(Block* blk) override {
   label(blk);
   blk->visit(
     [&](uint32_t lineno) {
       if (g_opts.linenoEnabled) {
         doIndent();
         // We list -1 as the character position since PHP's parser does not
         // include this information.
         folly::format(&out, ".srcloc {}:-1,{}:-1;\n", lineno, lineno);
       }
     },
     [&](const auto& bc) {
       bc.visit(*this);
     },
     [&](const auto& ex) {
       ex.visit(*this);
     }
   );
 }
Пример #30
0
/**
 * Add a field. Only allowed inside an object.
 */
void Saver::addField(string id) throw(io::IOException) {
	ASSERTP(isObject(state), "json: field only allowed inside an object!");
	doIndent();
	_out << '"';
	try {
		for(utf8::Iter i(id); i; i++)
			escape(*i);
	}
	catch(utf8::Exception& e) {
		ASSERTP(false, _ << "json: bad utf8 string: \"" << id << "\"");
	}
	_out << '"';
	if(isReadable())
		_out << ": ";
	else
		_out << ":";
	stack.push(state);
	state = FIELD;
}