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

void File::validateKey ( const Key key  )  throw (YAPETException,YAPETInvalidPasswordException) [protected]

Validates the given key.

Validates the key provided by reading the file header, decrypting it and comparing the control string of the file header with the string RECOG_STR. If those operations succeed, the key is considered valid. In case of an error, an exception is thrown.

Since this method relies on readHeader(), the file type is checked automatically.

Parameters:
key the key to validate against the file.

Definition at line 597 of file file.cc.

References YAPET::FileHeader::control, YAPET::Crypt::decrypt(), YAPET::HEADER_CONTROL_SIZE, and readHeader().

Referenced by File().

                                                        {

    Crypt crypt(key);
    BDBuffer* enc_header = NULL;
    Record<FileHeader>* dec_header = NULL;
    FileHeader* ptr_dec_header = NULL;

    try {
      enc_header = readHeader();
      dec_header = crypt.decrypt<FileHeader>(*enc_header);
      ptr_dec_header = *dec_header;
    } catch (YAPETEncryptionException& ex) {
      if (enc_header != NULL) delete enc_header;
      if (dec_header != NULL) delete dec_header;
      throw YAPETInvalidPasswordException();
    } catch (YAPETException& ex) {
      if (enc_header != NULL) delete enc_header;
      if (dec_header != NULL) delete dec_header;
      throw;
    }

    int retval = memcmp(ptr_dec_header->control,
                  CONTROL_STR,
                  HEADER_CONTROL_SIZE);
    delete enc_header;
    delete dec_header;
    if (retval != 0)
      throw YAPETInvalidPasswordException();
}


Generated by  Doxygen 1.6.0   Back to index