HTML Data Port

© 2005 Goetz Heller

Table of Contents Examples Source Code Subclass Template Copyright Note back

hashAlgorithm: An Abstract Base Class

hashAlgorithm is a generic helper class whose primary purpose is to manage hash algorithms. Its design was losely inspired by that of Microsoft's abstract .Net class HashAlgorithm. It works as an abstract base class from which concrete hash algorithms are derived via prototype inheritance. Instances of a concrete hash algorithm class should not be created directly using the new operator - use hashAlgorithm as a class factory and call hashAlgorithm.create() instead passing the name of the hash algorithm as parameter. This ensures that the new instance will be initialized properly. Furthermore, a loader function can be installed which requests the JavaScript code of an algorithm from a server if it has not yet been installed (load on demand).

Any hash algorithm to be managed by this class is required to do the following:

These requirements can be easily satisfied by using code templates. For an example, see MD5 JavaScript source code.

Replacing the protoype provides instances of the installed hash algorithm with the following: