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

BDBuffer * File::readHeader (  )  const throw (YAPETException) [protected]

Reads the encrypted header.

Reads the encrypted header from the file. It also checks whether or not the file is of the expected type by reading the recognition string. If the string read does not match the one predefined, it throws an YAPETException.

The memory occupied by the BDBuffer returned has to be freed by the caller.

Returns:
pointer to a BDBuffer holding the encrypted file header. The memory occupied has to be freed by the caller.

Definition at line 564 of file file.cc.

References fd, read(), and seekAbs().

Referenced by getMasterPWSet(), initFile(), preparePWSave(), and validateKey().

                                             {
    seekAbs(0);

    char* buff = (char*) alloca(strlen(RECOG_STR));
    if (buff == NULL)
      throw YAPETException(_("Memory exhausted"));

    int retval = ::read(fd, buff, strlen(RECOG_STR));
    if (retval == -1)
      throw YAPETException(strerror(errno));

    if (((size_t)retval) != strlen(RECOG_STR) )
      throw YAPETException(_("File type not recognized"));

    retval = memcmp(RECOG_STR, buff, strlen(RECOG_STR));
    if (retval != 0)
      throw YAPETException(_("File type not recognized"));

    return read();
}


Generated by  Doxygen 1.6.0   Back to index