Skip to content

Construct a salting SaltShaker

This operation builds a SaltShaker instance whose _dateParts dictionary is populated from a caller-supplied create date, which is the only state SaltHash (OP-HU-03) needs to embed that date into a hash string. In-repo, SystemHashService.ComputeHash is the sole caller, passing DateTime.Now.

Field Value
Operation ID OP-HU-01
Trigger Caller needs to salt a hash (in-repo: SystemHashService.ComputeHash, passing DateTime.Now)
Inputs createDate (DateTime)
Outputs SaltShaker instance with _random and populated _dateParts
Primary components SaltShaker.SaltShaker(DateTime createDate)
Entry point src/SAIF.NetCore.HashUtil/SAIF.NetCore.HashUtil/SaltShaker.cs

Steps

  1. Chain to the parameterless constructor, which creates a new System.Random instance used later for insertion positions and pad characters.
  2. Create the _dateParts dictionary.
  3. For each date part, format createDate with the current culture and hex-encode it, inserting entries in this order: Minute ("mm"), Year ("yyyy"), Day ("dd"), Millisecond ("fff"), Second ("ss"), Hour ("HH", 24-hour), Month ("MM") (BR-HU-02, BR-HU-03).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Caller needs to salt a hash]) --> S1["Chain to parameterless constructor:<br>create System.Random"]
    S1 --> S2[Create _dateParts dictionary]
    S2 --> S3["Hex-encode each date part in<br>Minute, Year, Day, Millisecond,<br>Second, Hour, Month order"]
    S3 --> EndOk([Instance ready for SaltHash])

Failure and edge-case behavior

  • No explicit error handling exists in this constructor; a null createDate is not possible (DateTime is a value type), so this operation has no documented failure path of its own.

Sources

  • src/SAIF.NetCore.HashUtil/SAIF.NetCore.HashUtil/SaltShaker.cs
  • src/SAIF.NetCore.SystemHash/SAIF.NetCore.SystemHash/SAIF.NetCore.SystemHash/SystemHashService.cs