Skip to content

Commit

Permalink
Adds some rudimentary code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dannygb committed May 22, 2016
1 parent 8130c3e commit 258dcd9
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 7 deletions.
8 changes: 8 additions & 0 deletions KeePit/aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ Aes::Aes()
{
}

/// \brief Aes::decrypt
/// Decrypts an AES byte array using CryptoPP
/// \param pbAesKey The Aes key used to decrypt the file
/// \param keysize The size of the key
/// \param pbEncryptionIV The encryption IV
/// \param pbFileContent The pointer to a byte array containing the Aes encrypted content
/// \param contentSize The size of the content
/// \return A string containing the decrypted file content
string Aes::decrypt(byte * pbAesKey, uint keysize, byte* pbEncryptionIV, byte* pbFileContent, uint contentSize) {

string recovered;
Expand Down
5 changes: 5 additions & 0 deletions KeePit/arrayextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ ArrayExtensions::ArrayExtensions()
{
}

/// \brief ArrayExtensions::toVector
/// Converts a pointer to a char array into a Vector
/// \param source The source pointer to a char array
/// \param size The size of the array
/// \return A vector containing the contents of the char array
vector<char> ArrayExtensions::toVector(char* source, unsigned int size)
{
vector<char> destination;
Expand Down
9 changes: 9 additions & 0 deletions KeePit/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Base64::Base64()
{
}

/// \brief Base64::base64_encode
/// Base64 encodes the given pointer to the char array
/// \param buf The buffer to encode
/// \param bufLen The length of the buffer
/// \return A string containing the base64 encoded content
std::string Base64::base64_encode(char const* buf, unsigned int bufLen) {
std::string ret;
int i = 0;
Expand Down Expand Up @@ -76,6 +81,10 @@ std::string Base64::base64_encode(char const* buf, unsigned int bufLen) {
return ret;
}

/// \brief Base64::base64_decode
/// Decodes a base64 string
/// \param encoded_string The encoded string
/// \return A vector of char containing the encoded content
std::vector<char> Base64::base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
Expand Down
35 changes: 30 additions & 5 deletions KeePit/bytestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ typedef unsigned char byte;
#define BYTESIZE 4
#define SHORTSIZE 2

/// \brief ByteStream::ByteStream
/// A container for a byte array
/// \param memblock The array to stream
/// \param size The size of the array
ByteStream::ByteStream(char* memblock, uint size)
{
vector<char> b(memblock, memblock + size);
buffer = b;
pos = 0;
}

/// \brief ByteStream::~ByteStream
/// ByteStream destructor
ByteStream::~ByteStream()
{
for(uint i = 0; i<buffer.size(); i++)
Expand All @@ -24,7 +30,10 @@ ByteStream::~ByteStream()
ArrayExtensions::Reset(buffer);
}

// Static method that reads only a byte from the given memblock array
/// \brief ByteStream::ReadByte
/// Static method that reads only a byte from the given memblock array
/// \param memblock The char array to read from
/// \return A uint containing the byte read
uint ByteStream::ReadByte(char* memblock)
{
int tmpPos = 0;
Expand All @@ -45,7 +54,11 @@ uint ByteStream::ReadByte(char* memblock)
return result;
}

// Reads a byte from the array given in the ctor and advances the pos
///
/// \brief ByteStream::ReadByte
/// Reads a byte from the array given in the ctor and advances the pos
/// \return
///
uint ByteStream::ReadByte()
{
uint result = 0;
Expand All @@ -64,7 +77,11 @@ uint ByteStream::ReadByte()
return result;
}

// Reads a ushort from the array given in the ctor and advances the pos
///
/// \brief ByteStream::ReadShort
/// Reads a ushort from the array given in the ctor and advances the pos
/// \return
///
ushort ByteStream::ReadShort()
{
ushort result = 0;
Expand All @@ -83,7 +100,11 @@ ushort ByteStream::ReadShort()
return result;
}

// Reads 1 byte at a time from the array given in the ctor
///
/// \brief ByteStream::Read
/// Reads 1 byte at a time from the array given in the ctor
/// \return
///
char ByteStream::Read()
{
char result = buffer[pos];
Expand All @@ -92,7 +113,11 @@ char ByteStream::Read()
return result;
}

// Returns the current position in the array we have read to
///
/// \brief ByteStream::GetPosition
/// Returns the current position in the array we have read to
/// \return
///
int ByteStream::GetPosition()
{
return pos;
Expand Down
23 changes: 23 additions & 0 deletions KeePit/compositekey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ struct String {
size_t length;
};

///
/// \brief CompositeKey::CompositeKey
/// \param pbKey
/// \param pbKeyFile
///
CompositeKey::CompositeKey(vector<char> pbKey, vector<char> pbKeyFile)
{
m_pbKey = pbKey;
Expand All @@ -51,6 +56,12 @@ CompositeKey::CompositeKey(vector<char> pbKey, vector<char> pbKeyFile)
}
}

///
/// \brief CompositeKey::generateKey32
/// \param pbKeySeed32
/// \param uNumRounds
/// \return
///
vector<char> CompositeKey::generateKey32(vector<char> pbKeySeed32, ulong uNumRounds) {
assert(pbKeySeed32.size() == MASTER_KEY_SIZE);
if(pbKeySeed32.size() != MASTER_KEY_SIZE) {
Expand Down Expand Up @@ -85,6 +96,11 @@ vector<char> CompositeKey::generateKey32(vector<char> pbKeySeed32, ulong uNumRou
return pbTrf32;
}

///
/// \brief CompositeKey::createRawCompositeKey
/// \param key
/// \return
///
vector<char> CompositeKey::createRawCompositeKey(vector<char> key) {

SHA256 sha256;
Expand All @@ -93,6 +109,13 @@ vector<char> CompositeKey::createRawCompositeKey(vector<char> key) {
return hash;
}

///
/// \brief CompositeKey::transformKey
/// \param pbOriginalKey32
/// \param pbKeySeed32
/// \param uNumRounds
/// \return
///
vector<char> CompositeKey::transformKey(vector<char> pbOriginalKey32, vector<char> pbKeySeed32, ulong uNumRounds) {
if(pbOriginalKey32.size() != MASTER_KEY_SIZE) throw new std::exception();
assert((pbKeySeed32.size() == MASTER_KEY_SIZE));
Expand Down
71 changes: 70 additions & 1 deletion KeePit/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,53 @@ const uint FileVersionCriticalMask = 0xFFFF0000;
const uint FileVersion32 = 0x00030001;
PasswordEntryModel* model;

///
/// \brief Database::Database
/// \param parent
///
Database::Database(QObject *parent) :
QObject(parent)
{
}

///
/// \brief Database::~Database
///
Database::~Database() {
}

///
/// \brief Database::deleteFile
/// \param filePath
///
void Database::deleteFile(QString filePath) {
FileHandler::deleteFile(filePath);
}

///
/// \brief Database::loadHome
///
void Database::loadHome() {
model->removeRows(0, model->rowCount());
for(uint i=0;i<dataTree.size();i++) {
model->addPasswordEntry(dataTree[i]->passwordEntry());
}
}

///
/// \brief Database::search
/// \param name
///
void Database::search(QString name) {
foundAny = false;
searchInternal(name, dataTree);
}

///
/// \brief Database::searchInternal
/// \param name
/// \param node
///
void Database::searchInternal(QString name, vector<TreeNode*> node) {
for(uint i=0;i<node.size();i++) {
QString strTitle = node[i]->passwordEntry().title();
Expand All @@ -130,6 +153,12 @@ void Database::searchInternal(QString name, vector<TreeNode*> node) {
}
}

///
/// \brief Database::reloadBranch
/// \param uuid
/// \param entryType
/// \return
///
QString Database::reloadBranch(QString uuid, int entryType)
{
QString retVal;
Expand Down Expand Up @@ -162,6 +191,10 @@ QString Database::reloadBranch(QString uuid, int entryType)
return retVal;
}

///
/// \brief Database::selectBranch
/// \param uuid
///
void Database::selectBranch(QString uuid)
{
if(getChildBranch(uuid, dataTree)) {
Expand All @@ -172,6 +205,12 @@ void Database::selectBranch(QString uuid)
}
}

///
/// \brief Database::getChildBranch
/// \param uuid
/// \param currentBranch
/// \return
///
bool Database::getChildBranch(QString uuid, vector<TreeNode*> currentBranch)
{
TreeNode* node;
Expand All @@ -192,6 +231,12 @@ bool Database::getChildBranch(QString uuid, vector<TreeNode*> currentBranch)
return false;
}

///
/// \brief Database::getMyBranch
/// \param uuid
/// \param currentBranch
/// \return
///
bool Database::getMyBranch(QString uuid, vector<TreeNode*> currentBranch)
{
TreeNode* node;
Expand All @@ -212,13 +257,20 @@ bool Database::getMyBranch(QString uuid, vector<TreeNode*> currentBranch)
return false;
}

///
/// \brief Database::createModel
/// \return
///
PasswordEntryModel* Database::createModel()
{
model = new PasswordEntryModel();

return model;
}

///
/// \brief Database::closeFile
///
void Database::closeFile() {
if(m_dbState != open) {
return;
Expand All @@ -232,6 +284,12 @@ void Database::closeFile() {
m_dbState = closed;
}

///
/// \brief Database::openFile
/// \param url
/// \param password
/// \param passKey
///
void Database::openFile(QString url, QString password, QString passKey) {

if(m_dbState == open) {
Expand Down Expand Up @@ -444,6 +502,11 @@ void Database::openFile(QString url, QString password, QString passKey) {
return;
}

///
/// \brief Database::readPayload
/// \param read
/// \param payload
///
void Database::readPayload(vector<char>* read, vector<char> payload) {

HashedBlockStream *hashedStream = new HashedBlockStream(payload, false, 0, true);
Expand All @@ -462,7 +525,13 @@ void Database::readPayload(vector<char>* read, vector<char> payload) {
assert (hashedStream == 0);
}

// Read the header information from the stream
///
/// \brief Database::readHeaderField
/// Read the header information from the stream
/// \param byteStream
/// \param endOfHeaderReached
/// \param readError
///
void Database::readHeaderField(ByteStream* byteStream, bool* endOfHeaderReached, bool *readError)
{
char btFieldID = byteStream->Read();
Expand Down
18 changes: 18 additions & 0 deletions KeePit/filehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@

using namespace std;

///
/// \brief FileHandler::FileHandler
///
FileHandler::FileHandler()
{
}

///
/// \brief FileHandler::deleteFile
/// \param filePath
///
void FileHandler::deleteFile(QString filePath)
{
remove(filePath.toStdString().c_str());
}

///
/// \brief FileHandler::readFile
/// \param filePath
/// \param size
/// \return
///
char* FileHandler::readFile(QString filePath, std::streampos &size)
{
ifstream file;
Expand Down Expand Up @@ -61,6 +74,11 @@ char* FileHandler::readFile(QString filePath, std::streampos &size)
}*/

///
/// \brief FileHandler::fileExists
/// \param fileName
/// \return
///
bool FileHandler::fileExists(const char* fileName)
{
ifstream infile(fileName);
Expand Down
Loading

0 comments on commit 258dcd9

Please sign in to comment.