This documentation is against the first Safe Pad release, version 1.0.
In this article I am going to cover how the code is structured. To demonstrate the code structure I will use the Architectural Dependency diagrams in Visual Studio 2012.
The main solution file is split into 3 projects. There is the SafePadClientLibrary which contains the code for encrypting the documents, compression, and the handling of the SafePad file format. The domain objects in this library contain all the important routines for making the project work.
The SafePad.exe project contains all the user interface elements of the application. SafePad is implemented with .NET 4.5 and WinForms.
SafePad.Tests.Unit currently contains unit tests for the crypto providers and domain objects (file format, encryption, password management etc).
The SafePad.exe project is the main entry point to the application. This project contain the WinForms user interface elements. Currently there are 2 forms. MainForm is the main application window containing the RichText editor, menus, and dockable toolbar strips. The properties namespace also contains the resource file with the application text. Currently English is the only supported language, but it could easily be made to manage foreign languages.
The SafePadClientLibrary project is where all the code that handles the main functionality of the application lies. The CrytoProviders namespace contains the implementation of AES256 and SHA256. The DomainObjects namespace contains everything else. The 2 main classes here are Document and Password.
The Password class is the container that stores hashes of the 2 user inputted passwords. The passwords are never stored in the clear. As soon as the user inserts them onto the password dialog form, they are hashed.
The Document class is the object that handles the loading and saving of documents, and as you can see from the diagram above this is the class that has the most dependencies on the other objects. GZipCompression is a class that compresses and decompresses bytes arrays. FileProxy is a wrapper over the FileStream classes in .NET. The reason this is in a separate class is because by having the IFileProxy interface we can inject an alternative implementation in the unit tests so that the tests don’t hit the file system.
The ByteHelpers class contains some static helper methods for comparing, Creating, and combining byte arrays.
The SafePad.Tests.Unit project contains all the unit tests for the application. At the moment, the only part of the application that has test coverage is the SafePadClientLibrary as this is the main heart of the application. Test coverage for this library is at 78.7%. The user interface elements of SafePad don’t currently have any unit tests, but I would like to add some coded UI Tests. All the unit tests are written using MSTest.
All of the projects have Microsoft Code Analysis set up on them. The code analysis ruleset is in the same folder as the solution files. The code analysis file is very strict, I have all rules set to Errors. This means if any rule is violated, it will break the build. This is a great way to ensure code is being developed to the same standards. I also used CodeRush in the construction of the application.