HTML Data Port

© 2005 Goetz Heller

Table of Contents Description Examples Source Code Copyright Note back

hashAlgorithm: An Abstract Base Class - JavaScript Subclass Template

  /// JavaScript template for message digest algorithm
  ///
  /// Goetz Heller
  /// Dr.Heller Information Management
  /// 08.02.2005
 
  /// Dependencies
  ///   genhash.js

// class system.security.encryption.hash.XXX - replace with class name

try {
  if (system.security.encryption.hash.XXX == null) {
    throw new Error('');
  }
} catch(e) { // don't install twice

  // dependencies
  try {
    if (core.toString().length > 0) {}
  } catch(e) {
    throw new Error('XXX: class \'core\' not installed');
  }

// get base class
var baseClass = core.getClassByID('system.security.encryption.hash.hashAlgorithm');

// constructor
var XXX = function() {};

// provide for class information
XXX.classID = function() {
  return 'system.security.encryption.hash.XXX';
};

//disallow subclassing
XXX.isFinal = function() {
  return true;
};

// define class constants
XXX.iInputBlockSize = 64;
XXX.iOutputBlockSize = 16;
XXX.hashSize = 128;
  
// make it as subclass of hashAlgorithm
core.derive(XXX, baseClass);

// setup data structures of class instance
XXX.prototype.initialize = function(arg0, arg1, ...) {
  // ...
  // setup baseclass instance members
  core.getClassByID('system.security.encryption.hash.hashAlgorithm').prototype.initialize.call(this, parm1, parm2, ...);
};

// resets the XXX data structures. Begins an XXX operation, writing a new context.
XXX.prototype.reset = function() {
  // reset baseclass data structures
  core.getClassByID('system.security.encryption.hash.hashAlgorithm').prototype.reset.call(this);
  // reset instance properties
  // ...
  // subclass specific resetting
  //...
  return this;
};

// XXX finalization. Ends an XXX message-digest operation, writing
// the message digest and zeroizing the context. Returns digest as string.
XXX.prototype.hashFinal = function() {
  // do class specific finalization
  // ...
  // build the hash string
  buildHash.call(this);
  return this.hash;
};

// XXX block update operation. Continues an XXX message-digest operation,
// processing another message block, and updating the context.
XXX.prototype.hashCore = function(inp, ibStart, cbSize) 
{
  // implement blockwise message digestion
  // ...
};

// install class
core.installClass(XXX);

} // end catch