In a previous article on Safe Pad I explained why I decided to write a little application called Safe Pad which I have open sourced on Code Plex under the GNU Public license.

This documentation is against the first Safe Pad release, version 1.0.

Safe Pad : Rich Text Editor with strong encryption.
Safe Pad : Rich Text Editor with strong encryption.

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.

Safe Pad : Solution Structure
Safe Pad : Solution Structure

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).

SafePad.exe Project

Safe Pad : Solution Structure
Safe Pad : Solution Structure

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.

SafePadClientLibrary.dll Project

Safe Pad : Solution Structure
Safe Pad : Solution Structure

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.

SafePad.Tests.Unit

Safe Pad : Solution Structure
Safe Pad : Solution Structure

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.

Safe Pad : Unit Tests
Safe Pad : Unit Tests

Code Analysis

Safe Pad : Static Code Analysis
Safe Pad : Static Code Analysis

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.

Participate with Coding in the Trenches on Facebook
Participate with Coding in the Trenches on Facebook by Click the button above.
Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s