summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-13 15:07:21 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-13 15:07:21 +0400
commit802410f7a3bdf2db3823f96e122bf1db45bf6a85 (patch)
treeb761182cd6a6cf47e75b168614b414fd1b5e089e
parent34b47f8e08eff519f6c8372f2e4ce5b24267614c (diff)
parentc113e7b5f46a3434f017de3f2c9f83a002b246f1 (diff)
Merge branch 'PARSER'
-rw-r--r--CryptClass/AESCrypt.cpp1
-rw-r--r--CryptClass/AbstractSKA.hpp13
-rw-r--r--CryptClass/HASHCrypt.cpp53
-rw-r--r--CryptClass/HASHCrypt.hpp26
-rw-r--r--ParserClass/AbstractIDManager.cpp39
-rw-r--r--ParserClass/AbstractIDManager.hpp59
-rw-r--r--ParserClass/FileManContainer/FileManContainer.cpp25
-rw-r--r--ParserClass/FileManContainer/FileManContainer.hpp46
-rw-r--r--ParserClass/FileManContainer/Website.cpp56
-rw-r--r--ParserClass/FileManContainer/Website.hpp78
-rw-r--r--ParserClass/FileManParser.cpp133
-rw-r--r--ParserClass/FileManParser.hpp58
-rw-r--r--main.cpp39
13 files changed, 580 insertions, 46 deletions
diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp
index 5a1e3eb..4f7309e 100644
--- a/CryptClass/AESCrypt.cpp
+++ b/CryptClass/AESCrypt.cpp
@@ -21,6 +21,7 @@ AESCrypt::AESCrypt(){
//Destructor
AESCrypt::~AESCrypt(){
+
}
diff --git a/CryptClass/AbstractSKA.hpp b/CryptClass/AbstractSKA.hpp
index ca7230b..7622ab4 100644
--- a/CryptClass/AbstractSKA.hpp
+++ b/CryptClass/AbstractSKA.hpp
@@ -7,29 +7,27 @@
* Specify which method the algorithm must be implement.
*
*/
+
#ifndef __AbstractSKA__
#define __AbstractSKA__
+
+//----- std -----
#include <string>
+
/**
* @class AbstractSKA AbstractSKA.hpp "/CryptClass/AbstractSKA.hpp"
* @brief Class for Symmetric-Key Algorithm (SKA)
* @author manzerbredes
*
- * This class should not be instanciate directly.
+ * This class should not be instantiate directly.
*
*/
-
class AbstractSKA {
public:
- AbstractSKA(){
- }
- ~AbstractSKA(){
- }
-
/**
* @brief Encrypt data.
*
@@ -42,6 +40,7 @@ class AbstractSKA {
*/
virtual std::string encrypt(std::string key, std::string data) = 0;
+
/**
* @brief Decrypt data.
*
diff --git a/CryptClass/HASHCrypt.cpp b/CryptClass/HASHCrypt.cpp
index cd0dab6..eed9cb5 100644
--- a/CryptClass/HASHCrypt.cpp
+++ b/CryptClass/HASHCrypt.cpp
@@ -8,13 +8,12 @@
*
*/
+
//----- class -----
#include "HASHCrypt.hpp"
-
-
//Constructor
HASHCrypt::HASHCrypt(){
}
@@ -25,6 +24,7 @@ HASHCrypt::~HASHCrypt(){
+//Contruct MD5 over 128 bits and put it into digest
void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){
//Digest size controller
@@ -37,6 +37,8 @@ void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){
}
+
+//Contruct SHA-256 and put it into digest
void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){
//Digest size controller
@@ -50,27 +52,6 @@ void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){
}
-//Check the size of the digest
-void HASHCrypt::checkDigestSize(int sizeRequired, int size){
- try{
- if(size !=sizeRequired){
- throw this->getInvalidDigestSizeError(sizeRequired, size);
- }
-
- }
- catch(std::string erreur){
- std::cerr << erreur <<std::endl;
- std::exit(EXIT_FAILURE);
- }
-}
-
-//Make the error
-std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){
- std::ostringstream erreurStream;
- erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)";
- return erreurStream.str();
-}
-
//Compare 2 digest (same size)
bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){
@@ -96,6 +77,7 @@ bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){
}
+
//Convert digest to string
std::string HASHCrypt::digestToString(byte* digest, int size){
@@ -107,3 +89,28 @@ std::string HASHCrypt::digestToString(byte* digest, int size){
return output;
}
+
+
+
+//Check the size of the digest
+void HASHCrypt::checkDigestSize(int sizeRequired, int size){
+ try{
+ if(size !=sizeRequired){
+ throw this->getInvalidDigestSizeError(sizeRequired, size);
+ }
+
+ }
+ catch(std::string erreur){
+ std::cerr << erreur <<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+}
+
+
+
+//Make the error
+std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){
+ std::ostringstream erreurStream;
+ erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)";
+ return erreurStream.str();
+}
diff --git a/CryptClass/HASHCrypt.hpp b/CryptClass/HASHCrypt.hpp
index 2c17d3d..3eafb2f 100644
--- a/CryptClass/HASHCrypt.hpp
+++ b/CryptClass/HASHCrypt.hpp
@@ -45,27 +45,31 @@ class HASHCrypt{
*/
~HASHCrypt();
+
/**
* @brief Create an MD5 over 128 bits on a digest array of bytes.
*
* @param chain : Chain to hash
* @param digest : An array of bytes (8 bits)
- * @param size : Length of the array digest
+ * @param size : Length of digest
*
* **Warning** digest will be modified.
* Digest must be an array of byte with 16 entries
+ * Invalid size can cause "Segmentation Fault"
*/
void getMD5_128(std::string chain, byte* digest, int size);
+
/**
* @brief Create an SHA over 256 bits on a digest array of bytes.
*
* @param chain : Chain to hash
* @param digest : An array of bytes (8 bits)
- * @param size : Length of the array digest
+ * @param size : Length of digest
*
* **Warning** digest will be modified.
* Digest must be an array of byte with 32 entries
+ * Invalid size can cause "Segmentation Fault"
*/
void getSHA_256(std::string chain, byte* digest, int size); //Return SHA_256
@@ -73,14 +77,15 @@ class HASHCrypt{
/**
* @brief Convert digest to a string of HEX characters
*
- * @param digest : An array of bytes (8 bits)
- * @param size : Length of the array digest
+ * @param digest : an array of bytes (8 bits)
+ * @param size : length of digest
*
- * @return a string of hex digest equivalent
+ * @return return a string of hex digest equivalent
*
- * Digest must be an array of byte with 16 entries
+ * Digest must be an array of byte.
*/
- std::string digestToString(byte* digest, int size); //Return a string of a digest
+ std::string digestToString(byte* digest, int size); //Return a string
+
/**
* @brief Compare 2 digest
@@ -89,10 +94,11 @@ class HASHCrypt{
* @param digest2 : An array of bytes (8 bits)
* @param size : Length of the array digest1 or digest2
*
- * @return a boolean if digest1 equals to digest2
+ * @return return a boolean (true if digest1 equals to digest2 and false else)
*
* **Warning** if sizeof(digest1) != sizeof(digest 2) : segmentation fault !
* Compare the two digest.
+ *
*/
bool compareDigest(byte* digest1, byte* digest2, int size);
@@ -105,7 +111,7 @@ class HASHCrypt{
* @param sizeRequired : Digest size expected
* @param size : Given digest size
*
- * Throw an exception, and stop the programm if
+ * Throw an exception, and stop the program if
* sizeRequired != size
* Use getInvalidDigestSizeError method.
*/
@@ -113,7 +119,7 @@ class HASHCrypt{
/**
- * @brief Make and error message.
+ * @brief Make "invalid digest size" error message.
*
* @param sizeRequired : Digest size expected
* @param size : Given digest size
diff --git a/ParserClass/AbstractIDManager.cpp b/ParserClass/AbstractIDManager.cpp
new file mode 100644
index 0000000..01e3c3d
--- /dev/null
+++ b/ParserClass/AbstractIDManager.cpp
@@ -0,0 +1,39 @@
+/**
+ * @file AbstractIDManager.cpp
+ * @brief AbstractIDManager class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all implémentations of AbstractIDManager class.
+ *
+ */
+
+#include "AbstractIDManager.hpp"
+
+AbstractIDManager::AbstractIDManager(){
+ this->id=this->generateId();
+}
+
+AbstractIDManager::AbstractIDManager(std::string id){
+ this->id=id;
+}
+AbstractIDManager::~AbstractIDManager(){
+ this->id=id;
+}
+
+
+
+void AbstractIDManager::setId(std::string id){
+ this->id = id;
+}
+
+std::string AbstractIDManager::generateId(){
+ boost::uuids::uuid uuid = boost::uuids::random_generator()();
+ std::stringstream ss;
+ ss << uuid;
+ return ss.str();
+}
+
+std::string AbstractIDManager::getId(){
+ return this->id;
+}
diff --git a/ParserClass/AbstractIDManager.hpp b/ParserClass/AbstractIDManager.hpp
new file mode 100644
index 0000000..a18d1b2
--- /dev/null
+++ b/ParserClass/AbstractIDManager.hpp
@@ -0,0 +1,59 @@
+/**
+ * @file AbstractIDManager.hpp
+ * @brief AbstractIDManager class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all definitions of AbstractIDManager class.
+ * If you want to manage id in class (like container), use
+ * this class as superclass.
+ *
+ */
+
+//----- std -----
+#include <string>
+#include <sstream>
+
+
+//----- boost -----
+#include <boost/uuid/uuid.hpp> // uuid class
+#include <boost/uuid/uuid_generators.hpp> // generators
+#include <boost/uuid/uuid_io.hpp> // streaming operators etc.
+
+
+
+
+/**
+ * @class AbstractIDManager AbstractIDManager.hpp "/CryptClass/AbstractIDManager.hpp"
+ * @brief Managing ID
+ * @author manzerbredes
+ *
+ * This class should not be instantiate directly.
+ *
+ */
+ class AbstractIDManager{
+
+
+ public:
+ //Constructor
+ AbstractIDManager();
+
+ //Constructor, init with id
+ AbstractIDManager(std::string);
+
+ //Destructor
+ ~AbstractIDManager();
+
+
+ //Getters and setters
+ std::string getId();
+ void setId(std::string id);
+
+
+ private:
+ //Generate and random id
+ std::string generateId();
+
+ std::string id; ///< String id attribute
+
+ };
diff --git a/ParserClass/FileManContainer/FileManContainer.cpp b/ParserClass/FileManContainer/FileManContainer.cpp
new file mode 100644
index 0000000..7f04be4
--- /dev/null
+++ b/ParserClass/FileManContainer/FileManContainer.cpp
@@ -0,0 +1,25 @@
+/**
+ * @file FileManContainer.cpp
+ * @brief FileManContainer class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all implementation of FileManContainer class.
+ *
+ */
+
+
+#include "FileManContainer.hpp"
+
+FileManContainer::FileManContainer(){
+}
+
+
+
+void FileManContainer::addWebsite(Website website){
+ this->websites.push_back(website);
+}
+
+std::vector<Website> FileManContainer::getWebsites(){
+ return this->websites;
+}
diff --git a/ParserClass/FileManContainer/FileManContainer.hpp b/ParserClass/FileManContainer/FileManContainer.hpp
new file mode 100644
index 0000000..d5be276
--- /dev/null
+++ b/ParserClass/FileManContainer/FileManContainer.hpp
@@ -0,0 +1,46 @@
+/**
+ * @file FileManContainer.hpp
+ * @brief FileManContainer class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all definitions of FileManContainer class.
+ *
+ */
+
+#ifndef __FileManContainer__
+#define __FileManContainer__
+
+//----- std -----
+
+#include <string>
+#include <vector>
+
+//----- class -----
+#include "Website.hpp"
+
+
+/**
+ * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp"
+ * @brief Class for manager all FileMan container (websites etc...)
+ * @author manzerbredes
+ *
+ *
+ *
+ */
+
+class FileManContainer{
+
+ public:
+ FileManContainer();
+
+ void addWebsite(Website website);
+ std::vector<Website> getWebsites();
+
+ private:
+
+ std::vector<Website> websites;
+};
+
+
+#endif
diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp
new file mode 100644
index 0000000..d54e28a
--- /dev/null
+++ b/ParserClass/FileManContainer/Website.cpp
@@ -0,0 +1,56 @@
+/**
+ * @file Website.cpp
+ * @brief Website class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all implementations of Website class.
+ *
+ */
+
+
+#include "Website.hpp"
+
+
+Website::Website(){
+
+}
+
+
+
+
+
+std::string Website::getTitle(){
+ return this->title;
+}
+std::string Website::getUrl(){
+ return this->url;
+}
+std::string Website::getUsername(){
+ return this->username;
+}
+std::string Website::getPassword(){
+ return this->password;
+}
+std::string Website::getDescription(){
+ return this->description;
+}
+
+
+
+
+void Website::setTitle(std::string title){
+ this->title = title;
+}
+void Website::setUrl(std::string url){
+ this->url = url;
+}
+void Website::setUsername(std::string username){
+ this->username = username;
+}
+void Website::setPassword(std::string password){
+ this->password = password;
+}
+void Website::setDescription(std::string description){
+ this->description = description;
+}
diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp
new file mode 100644
index 0000000..c370f3b
--- /dev/null
+++ b/ParserClass/FileManContainer/Website.hpp
@@ -0,0 +1,78 @@
+/**
+ * @file Website.hpp
+ * @brief Website class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all definitions of Website class.
+ *
+ */
+
+#ifndef __WEBSITE__
+#define __WEBSITE__
+
+#include <string>
+
+
+/**
+ * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp"
+ * @brief Class for quick open and close encrypted file.
+ * @author manzerbredes
+ *
+ * -----File organisation-----
+ *
+ * 16 first bytes : md5 of decrypted file
+ * rest of the file : data encrypted (ASE for now)
+ *
+ */
+
+#include <string>
+#include "AbstractIDManager.hpp"
+
+/**
+ * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp"
+ * @brief Class for quick open and close encrypted file.
+ * @author manzerbredes
+ *
+ * Container for website data.
+ *
+ */
+class Website : public AbstractIDManager {
+
+
+ public:
+
+ Website();
+
+ /**
+ * @brief Containner getters.
+ */
+
+ std::string getTitle();
+ std::string getUrl();
+ std::string getUsername();
+ std::string getPassword();
+ std::string getDescription();
+
+
+ /**
+ * @brief Containner setters.
+ */
+ void setTitle(std::string title);
+ void setUrl(std::string url);
+ void setUsername(std::string username);
+ void setPassword(std::string password);
+ void setDescription(std::string description);
+
+
+ private:
+
+ std::string title; ///< Title of the website
+ std::string url; ///< Url of the website
+ std::string username; ///< username of the account
+ std::string password; ///< password of the account
+ std::string description; ///< Description of the website
+};
+
+
+#endif
diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp
new file mode 100644
index 0000000..66e3c52
--- /dev/null
+++ b/ParserClass/FileManParser.cpp
@@ -0,0 +1,133 @@
+/**
+ * @file FileManParser.cpp
+ * @brief FileManParser class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all implementations of FileManParser class.
+ *
+ */
+
+
+#include "FileManParser.hpp"
+
+
+FileManParser::FileManParser(std::string data){
+ this->data=data;
+
+ try {
+ xercesc::XMLPlatformUtils::Initialize();
+ }
+ catch (const xercesc::XMLException& toCatch) {
+ // Do your failure processing here
+
+ }
+
+
+ xercesc::XercesDOMParser *parser = new xercesc::XercesDOMParser();
+ xercesc::MemBufInputSource myxml_buf((const XMLByte*)this->data.c_str(), this->data.size(), "dummy",false);
+
+ parser->parse("Doxygen/doc.xml");
+
+
+ this->document=parser->getDocument();
+ this->root=this->document->getDocumentElement();
+
+ this->initWebsites();
+
+
+
+}
+
+
+
+FileManContainer FileManParser::getContainer(){
+ return this->container;
+}
+
+
+std::string FileManParser::getData(){ return this->data;};
+
+
+
+void FileManParser::initWebsites(){
+
+ //Get websites élément
+ xercesc::DOMElement* websitesElement=this->getChildByTagName(this->root, "websites");
+
+ //Make list of website
+ xercesc::DOMNodeList* websiteList=websitesElement->getChildNodes();
+ XMLSize_t websiteCount = websiteList->getLength();
+
+
+ //Read the list of website
+ for(int i=0;i<websiteCount;i++){
+
+ xercesc::DOMNode* current=websiteList->item(i);
+ std::string TagName=xercesc::XMLString::transcode(current->getNodeName());
+
+ if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
+ Website newWebsite;
+
+ //Get id
+ XMLCh* idXMLCh=(XMLCh*)((xercesc::DOMElement*)current)->getAttribute((XMLCh*) xercesc::XMLString::transcode("id"));
+ //Convert id to string from XMLCh
+ std::string id=xercesc::XMLString::transcode(idXMLCh);
+
+ //Assign id
+ newWebsite.setId(id);
+
+ //Assign title
+ newWebsite.setTitle(\
+ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"));
+
+ //Assign url
+ newWebsite.setUrl(\
+ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"));
+
+ //Assign username
+ newWebsite.setUsername(\
+ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username"));
+
+ //Assign password
+ newWebsite.setPassword(\
+ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password"));
+
+ //Assign description
+ newWebsite.setDescription(\
+ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description"));
+
+ //Add website to container
+ this->container.addWebsite(newWebsite);
+
+ }
+ }
+}
+
+
+xercesc::DOMElement* FileManParser::getChildByTagName(xercesc::DOMElement* node, std::string TagName){
+ xercesc::DOMNodeList* nodeList=node->getChildNodes();
+ XMLSize_t nodeCount = nodeList->getLength();
+ xercesc::DOMElement* returnElement=NULL;
+
+ for(int i=0;i<nodeCount;i++){
+
+ xercesc::DOMNode* current=nodeList->item(i);
+ std::string currentTagName=xercesc::XMLString::transcode(current->getNodeName());
+
+ if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
+ if(currentTagName.compare(TagName)==0){
+ returnElement=dynamic_cast< xercesc::DOMElement* >( current );
+ break;
+ }
+ }
+ }
+
+ return returnElement;
+}
+
+
+std::string FileManParser::getContentOfChild(xercesc::DOMElement* node,std::string TagName){
+ xercesc::DOMElement* child=this->getChildByTagName(node,TagName);
+ return xercesc::XMLString::transcode(child->getTextContent());
+}
diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp
new file mode 100644
index 0000000..6a977db
--- /dev/null
+++ b/ParserClass/FileManParser.hpp
@@ -0,0 +1,58 @@
+/**
+ * @file FileManParser.hpp
+ * @brief FileManParser class definitions
+ * @author manzerbredes
+ * @date 11 Mars 2015
+ *
+ * Contain all definitions of FileManParser class.
+ *
+ */
+
+//----- std -----
+#include <iostream>
+#include <string>
+#include <vector>
+
+//----- class -----
+#include "Website.hpp"
+#include "FileManContainer.hpp"
+
+//----- xerces -----
+#include <xercesc/parsers/XercesDOMParser.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/framework/MemBufInputSource.hpp>
+#include <xercesc/sax/HandlerBase.hpp>
+#include <xercesc/util/XMLString.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+#include <xercesc/util/XercesDefs.hpp>
+
+
+
+class FileManParser{
+
+
+ public:
+ FileManParser(std::string data);
+
+
+
+ FileManContainer getContainer();
+
+ void initWebsites();
+
+ std::string getData();
+
+ xercesc::DOMElement* getChildByTagName(xercesc::DOMElement* node, std::string TagName);
+ std::string getContentOfChild(xercesc::DOMElement* node,std::string TagName);
+
+ private:
+
+ xercesc::DOMDocument* document; ///< contain the document
+
+ xercesc::DOMElement* root;
+
+ FileManContainer container; ///< contain all container
+
+ std::string data; ///< contain data to parse
+
+};
diff --git a/main.cpp b/main.cpp
index af9f31b..bae168f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -15,13 +15,13 @@
#include <iostream>
#include <string>
+#include <vector>
//----- class -----
-#include "AESCrypt.hpp"
-#include "HASHCrypt.hpp"
#include "FileManIOFile.hpp"
-
-
+#include "FileManParser.hpp"
+#include "FileManContainer.hpp"
+#include "Website.hpp"
/**
* @fn int main(int argc, char *argv[])
@@ -33,7 +33,30 @@
*/
int main(int argc, char *argv[]){
- std::string chaine="It's work !";
+
+
+
+ std::string xml="<?xml version=\"1.0\" standalone=\"yes\" ?>\n\
+<forgetIt> \n\
+<websites> \n\
+ \n\
+ </websites> \n\
+</forgetIt> \n\
+ ";
+
+
+ FileManParser parser(xml);
+
+
+
+ //std::cout << std::endl << parser.getData() << std::endl;
+
+
+
+
+
+
+ /*std::string chaine="It's work !";
std::string key="loic";
AESCrypt aes;
@@ -52,7 +75,11 @@ int main(int argc, char *argv[]){
fichier.read(key);
if(fichier.isReadable())
- std::cout << fichier.getData();
+ std::cout << fichier.getData();*/
+
+ FileManContainer container= parser.getContainer();
+ std::vector<Website> websites= container.getWebsites();
+ std::cout << websites.at(0).getId();
return 0;