Logo Search packages:      
Sourcecode: yapet version File versions  Download package

void File::initFile ( const Key key  )  throw (YAPETException) [protected]

Initializes an empty file.

Creates a header struct FileHeader and calls writeHeader. It then reads and decrypts the header in order to verify.

Parameters:
key reference to the key used to encrypt the header.

Definition at line 466 of file file.cc.

References YAPET::FileHeader::control, YAPET::Crypt::decrypt(), YAPET::HEADER_CONTROL_SIZE, lastModified(), mtime, YAPET::FileHeader::pwset, readHeader(), uint32_to_disk(), YAPET::FileHeader::version, and writeHeader().

Referenced by File(), and setNewKey().

                                                   {
    Crypt crypt(key);

    Record<FileHeader> header;
    FileHeader* ptr = header;
    ptr->version = 1;
    memcpy(ptr->control, CONTROL_STR, HEADER_CONTROL_SIZE);
    ptr->pwset = uint32_to_disk(time(NULL));

    mtime = lastModified();

    writeHeader(header, key);

    // Sanity checks
    BDBuffer* buff = readHeader();
    if (buff == NULL)
      throw YAPETException(_("EOF encountered while reading header"));

    Record<FileHeader>* dec_hdr = crypt.decrypt<FileHeader>(*buff);

    FileHeader* ptr_dec_hdr = *dec_hdr;

    int retval = memcmp(ptr_dec_hdr->control, ptr->control, HEADER_CONTROL_SIZE);
    if (retval != 0)
      throw YAPETException(_("Sanity check for control field failed"));

    delete buff;
    delete dec_hdr;
}


Generated by  Doxygen 1.6.0   Back to index