Esempio n. 1
0
void emitDeclaration(refVoidFunc etc, refObject type)
{ switch (toHook(car(type)))

//  An array or tuple type becomes a STRUCT name (see ORSON/SIZE).

  { case arrayHook:
    case tupleHook:
    { writeDirtyName(target, "type", typeSize(type));
      etc();
      break; }

//  The CHAR0 type becomes CHAR0 STRING (see ORSON/GLOBAL).

    case char0Hook:
    { writeFormat(target, "%s", char0String);
      etc();
      break; }

//  The CHAR1 type becomes CHAR1 STRING (see ORSON/GLOBAL).

    case char1Hook:
    { writeFormat(target, "%s", char1String);
      etc();
      break; }

//  The INT0 type becomes INT0 STRING (see ORSON/GLOBAL).

    case int0Hook:
    { writeFormat(target, "%s", int0String);
      etc();
      break; }

//  The INT1 type becomes INT1 STRING (see ORSON/GLOBAL).

    case int1Hook:
    { writeFormat(target, "%s", int1String);
      etc();
      break; }

//  The INT2 type becomes INT2 STRING (see ORSON/GLOBAL).

    case int2Hook:
    { writeFormat(target, "%s", int2String);
      etc();
      break; }

//  NULL, REF, and ROW types become pointers to C's VOID type.

    case nullHook:
    case referHook:
    case rowHook:
    { emitDeclaration(
       ({ void lambda()
          { writeChar(target, '*');
            etc(); }
          lambda; }),
       voidExternal);
      break; }
Esempio n. 2
0
 void write(FileStorage& fs) const
 {
     writeFormat(fs);
     fs << "name" << name
        << "max_iter" << max_iter
        << "threshold" << threshold;
 }
Esempio n. 3
0
 void write(FileStorage& fs) const
 {
     writeFormat(fs);
     fs << "name" << name
        << "max_bits" << max_bits
        << "exclude_range" << exclude_range
        << "cut" << static_cast<int>(cut);
 }
Esempio n. 4
0
 void write(FileStorage& fs) const
 {
     writeFormat(fs);
     fs << "name" << name
        << "samples" << samples
        << "lambda" << lambda
        << "random" << static_cast<int>(random);
 }
Esempio n. 5
0
void writeMatch(refMatch match)
{ refBuffer buffer = makeBuffer(stdout, 0);
  writeFormat(buffer, "[Match");
  writeBlank(buffer);
  writingObject(buffer, leftLayer(match));
  writeBlank(buffer);
  writingObject(buffer, leftType(match));
  writeBlank(buffer);
  writingObject(buffer, rightLayer(match));
  writeBlank(buffer);
  writingObject(buffer, rightType(match));
  writeChar(buffer, ']');
  writeBuffer(buffer);
  free(buffer); }
Esempio n. 6
0
    void write(FileStorage& fs) const
    {
        writeFormat(fs);
        fs << "training_params" << "{";
        write_params(fs);
        fs << "}";
        fs << "weights" << weights;
        fs << "means" << means;

        size_t i, n = covs.size();

        fs << "covs" << "[";
        for( i = 0; i < n; i++ )
            fs << covs[i];
        fs << "]";
    }
Esempio n. 7
0
status WAVEFile::writeInit(AFfilesetup setup)
{
	uint32_t	zero = 0;

	if (_af_filesetup_make_handle(setup, this) == AF_FAIL)
		return AF_FAIL;

	fh->seek(0, File::SeekFromBeginning);
	fh->write("RIFF", 4);
	fh->write(&zero, 4);
	fh->write("WAVE", 4);

	writeMiscellaneous();
	writeCues();
	writeFormat();
	writeFrameCount();
	writeData();

	return AF_SUCCEED;
}
Esempio n. 8
0
 //! write/read
 virtual void write(FileStorage& fs) const
 {
     writeFormat(fs);
     fs << "name" << name_
        << "regularization" << regularizationParameter;
 }
Esempio n. 9
0
void emitStatement(refObject term, set wraps)

//  PRE EMIT. Write an open brace if needed.

{ void preEmit(int hook)
  { if (isInSet(hook, wraps))
    { writeChar(target, '{'); }}

//  POST EMIT. Write a close brace if needed.

  void postEmit(int hook)
  { if (isInSet(hook, wraps))
    { writeChar(target, '}'); }}

//  Dispatch to an appropriate case based on TERM's outer hook.

   if (isPair(term))
   { switch (toHook(car(term)))

//  Write C code for a CASE clause.

    { case caseHook:
      { refObject subterm;
        preEmit(caseHook);
        term = cdr(term);
        writeFormat(target, "switch");
        writeChar(target, '(');
        emitExpression(car(term), 13);
        writeChar(target, ')');
        writeChar(target, '{');
        term = cdr(term);
        while (cdr(term) != nil)
        { emitLabels(car(term));
          term = cdr(term);
          subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, withSet); }
          writeFormat(target, "break");
          writeChar(target, ';');
          term = cdr(term); }
        subterm = car(term);
        if (isEffected(subterm))
        { writeFormat(target, "default");
          writeChar(target, ':');
          emitStatement(subterm, withSet); }
        writeChar(target, '}');
        postEmit(caseHook);
        break; }

//  Write C code for an IF clause.

      case ifHook:
      { refObject subterm;
        preEmit(ifHook);
        term = cdr(term);
        while (true)
        { writeFormat(target, "if");
          writeChar(target, '(');
          emitExpression(car(term), 13);
          writeChar(target, ')');
          term = cdr(term);
          subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, ifLastWithSet); }
          else
          { writeChar(target, ';'); }
          term = cdr(term);
          if (cdr(term) == nil)
          { subterm = car(term);
            if (isEffected(subterm))
            { writeFormat(target, "else");
              writeBlank(target);
              if (isCar(subterm, ifHook))
              { term = cdr(subterm); }
              else
              { emitStatement(subterm, lastWithSet);
                break; }}
            else
            { break; }}
          else
          { writeFormat(target, "else");
            writeBlank(target); }}
        postEmit(ifHook);
        break; }

//  Write C code for a LAST clause.

      case lastHook:
      { refObject subterm;
        preEmit(lastHook);
        term = cdr(term);
        while (term != nil)
        { subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, withSet); }
          term = cdr(term); }
        postEmit(lastHook);
        break; }

//  Write C code for a WHILE clause.

      case whileHook:
      { preEmit(whileHook);
        term = cdr(term);
        writeFormat(target, "while");
        writeChar(target, '(');
        emitExpression(car(term), 13);
        writeChar(target, ')');
        term = cadr(term);
        if (isEffected(term))
        { emitStatement(term, lastWithSet); }
        else
        { writeChar(target, ';'); }
        postEmit(whileHook);
        break; }

//  Write C code for a WITH clause.

      case withHook:
      { refObject frame;
        preEmit(withHook);
        term = cdr(term);
        frame = car(term);
        term = cdr(term);
        if (frame == nil)
        { emitVariableDeclarations(term);
          emitFunctionDefinitions(true, term);
          emitVariableDefinitions(nil, term);
          term = car(lastPair(term));
          if (isEffected(term))
          { emitStatement(term, withSet); }}
        else
        { emitFrameDeclaration(frame, term);
          emitVariableDeclarations(term);
          emitFunctionDefinitions(true, term);
          emitFramePush(frame, frameLength(term));
          emitFrameInitialization(frame, term);
          emitVariableDefinitions(frame, term);
          term = car(lastPair(term));
          if (isEffected(term))
          { emitStatement(term, withSet); }
          emitFramePop(frame); }
        postEmit(withHook);
        break; }

//  Other TERMs become C expressions.

      default:
      { if (isEffected(term))
        { emitExpression(term, 13);
          writeChar(target, ';'); }
        break; }}}
  else
  { if (isEffected(term))
    { emitExpression(term, 13);
      writeChar(target, ';'); }}}
Esempio n. 10
0
void writingObject(refBuffer buffer, refObject object)
{ if (object == nil)
  { writeFormat(buffer, "[Nil]"); }
  else
  { switch (tag(object))
    { case cellTag:
      { writeFormat(buffer, "[Cell %X]", object);
        return; }
      case characterTag:
      { writeCharacter(buffer, toCharacter(object));
        return; }
      case evenBinderTag:
      { writeFormat(buffer, "[EvenBinder %X]", object);
        return; }
      case hookTag:
      { writeFormat(buffer, "?%s", hookTo(object));
        return; }
      case hunkTag:
      { writeFormat(buffer, "[Hunk %X]", object);
        return; }
      case integerTag:
      { writeFormat(buffer, "%i", toInteger(object));
        return; }
      case jokerTag:
      { writeFormat(buffer, "[%s]", jokerTo(object));
        return; }
      case leftBinderTag:
      { writeFormat(buffer, "[LeftBinder %X]", object);
        return; }
      case markedTag:
      { writeFormat(buffer, "[...]");
        return; }
      case matchTag:
      { writeFormat(buffer, "[Match %X]", object);
        return; }
      case nameTag:
      { writeVisibleName(buffer, object);
        return; }
      case pairTag:
      { refObject pairs = object;
        tag(object) = markedTag;
        writeChar(buffer, '(');
        writingObject(buffer, car(pairs));
        pairs = cdr(pairs);
        while (pairs != nil)
        { writeBlank(buffer);
          writingObject(buffer, car(pairs));
          pairs = cdr(pairs); }
        writeChar(buffer, ')');
        tag(object) = pairTag;
        return; }
      case realTag:
      { writeFormat(buffer, "%.17E", toReal(object));
        return; }
      case rightBinderTag:
      { writeFormat(buffer, "[RightBinder %X]", object);
        return; }
      case stringTag:
      { writeQuotedString(buffer, toRefString(object));
        return; }
      default:
      { writeFormat(buffer, "[Tag%i %X]", tag(object), object);
        return; }}}}
Esempio n. 11
0
 //! write/read
 virtual void write(FileStorage& fs) const
 {
     writeFormat(fs);
     fs << "name" << name_
        << "affine_type" << int(fullAffine);
 }
Esempio n. 12
0
int main(int, char **)
{
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = pcsc_test_init();

    PRINT_TIME("CHip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

    LLA_ASSERT(chip->getCardType() == "DESFireEV1",
               "Chip is not an DESFireEV1, but is " + chip->getCardType() +
               " instead.");

    auto location_root_node = chip->getRootLocationNode();

    auto cmd = std::dynamic_pointer_cast<logicalaccess::DESFireISO7816Commands>(
            chip->getCommands());
    auto cmdev1 = std::dynamic_pointer_cast<logicalaccess::DESFireEV1ISO7816Commands>(
            chip->getCommands());
    LLA_ASSERT(cmd && cmdev1, "Cannot get correct command object from chip.");

    cmd->selectApplication(0x00);
    cmd->authenticate(0);

    cmd->erase();
    cmdev1->createApplication(0x521, logicalaccess::DESFireKeySettings::KS_DEFAULT, 3,
                              logicalaccess::DESFireKeyType::DF_KEY_AES,
                              logicalaccess::FIDS_NO_ISO_FID, 0, std::vector<unsigned char>());

    cmd->selectApplication(0x521);
    std::shared_ptr<logicalaccess::DESFireKey> key(new logicalaccess::DESFireKey());
    key->setKeyType(logicalaccess::DESFireKeyType::DF_KEY_AES);
    cmd->authenticate(0, key);
    LLA_SUBTEST_PASSED("Authenticate");

    logicalaccess::DESFireAccessRights ar;
    ar.readAccess = logicalaccess::TaskAccessRights::AR_KEY2;
    ar.writeAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    ar.readAndWriteAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    ar.changeAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    cmdev1->createStdDataFile(0x00, logicalaccess::EncryptionMode::CM_ENCRYPT, ar, 4, 0);


    cmd->authenticate(1, key);
    std::vector<unsigned char> data = {0x01, 0x02, 0x03, 0x04}, tmp;
    cmdev1->writeData(0, 0, data, logicalaccess::EncryptionMode::CM_ENCRYPT);

    cmd->authenticate(2, key);
    tmp = cmdev1->readData(0, 0, 4, logicalaccess::EncryptionMode::CM_ENCRYPT);
    LLA_ASSERT(std::equal(data.begin(), data.end(), tmp.begin()),
               "read and write data are different!");
    LLA_SUBTEST_PASSED("WriteRead");

    cmd->authenticate(0x00, key);
    cmd->deleteFile(0x00);

    cmd->authenticate(0x00, key);
    std::shared_ptr<logicalaccess::DESFireKey> newkey(
            new logicalaccess::DESFireKey("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03"));
    cmd->changeKey(0x00, newkey);
    LLA_SUBTEST_PASSED("ChangeKey");

    cmd->selectApplication(0x00);
    cmd->authenticate(0);
    cmd->deleteApplication(0x521);

    auto service = std::dynamic_pointer_cast<logicalaccess::AccessControlCardService>(
            chip->getService(logicalaccess::CardServiceType::CST_ACCESS_CONTROL));
    LLA_ASSERT(service, "Cannot retrieve access control service from chip.");

    auto location = std::make_shared<logicalaccess::DESFireLocation>();
    location->aid = 0x522;
    location->file = 0;
    auto ai = std::make_shared<logicalaccess::DESFireAccessInfo>();
    auto format = std::make_shared<logicalaccess::Wiegand26Format>();
    format->setUid(1000);
    format->setFacilityCode(67);

    service->writeFormat(format, location, ai, ai);
    auto formattmp = std::make_shared<logicalaccess::Wiegand26Format>();
    auto rformat = std::dynamic_pointer_cast<logicalaccess::Wiegand26Format>(
            service->readFormat(formattmp, location, ai));

    if (!rformat || rformat->getUid() != 1000 || rformat->getFacilityCode() != 67)
    THROW_EXCEPTION_WITH_LOG(std::runtime_error, "Bad format");
    LLA_SUBTEST_PASSED("ReadFormat");

    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}