1 public class SignatureComputer {
2 public EphemeralSignature sig4; //signature engines
3 public WhiplashSignature sig8; //signature engines
5 int[] enginesToUseForCheck;
7 public SignatureComputer() {
8 sig4 = new EphemeralSignature(); //default values
9 sig8 = new WhiplashSignature();
10 createEnginesToCheck();
14 * constructor to be used when some parsing has already taken place with the
15 * server-provides value <code>randomNumberSeed</code>.
17 * @param randomNumberSeed
18 * a non-negative number used for seeding the random number generator
19 * before starting to hash values.
21 * how the mail-text should be splitted into lines. (== what chars
24 public SignatureComputer(int randomNumberSeed, String separator) {
25 sig4 = new EphemeralSignature(randomNumberSeed,separator);
26 sig8 = new WhiplashSignature();
27 createEnginesToCheck();
31 * the constructor to be used most of the time. you can hand over the
32 * seed-string exactly as it is provided by the razor-server.
34 * @param seedAndSeparator
35 * a string containing the seed value for the RNG and a separator list
36 * (separated by ' <b>- </b>'). default value is
37 * <code>"7542-10"</code> which means server-seed 7542 and only one
38 * separator 10 (which is ascii '\n').
40 public SignatureComputer(String seedAndSeparator) {
41 sig4 = new EphemeralSignature(seedAndSeparator);
42 sig8 = new WhiplashSignature();
43 createEnginesToCheck();
49 public void createEnginesToCheck() {
50 enginesToUseForCheck = new int[2];
51 enginesToUseForCheck[0] = 4; //Ephemeral engine
52 enginesToUseForCheck[1] = 8;//Whiplash engine
55 public boolean isSigSupported(int sig) {
56 boolean found = false;
57 for (int i = 0; i < enginesToUseForCheck.length && !found; i++) {
58 if (enginesToUseForCheck[i] == sig) {
65 public boolean isSigSupported(String sig) {
66 return (sig != null && isSigSupported(Integer.parseInt(sig)));
69 public String getDefaultEngine() {
73 public Vector computeSigs(Vector EmailParts) {
74 if (EmailParts == null) return null;
76 Vector printableSigs = new Vector(); // vector of strings
77 for (int mailIndex = 0; mailIndex < EmailParts.size(); mailIndex++) {
78 String mail = EmailParts.elementAt(mailIndex);
80 if (mail == null) continue;
83 * Compute Sig for bodyparts that are cleaned.
85 for (int engineIndex = 0; engineIndex < enginesToUseForCheck.length; engineIndex++) {
86 int engineNo = enginesToUseForCheck[engineIndex];
91 sig = computeSignature(engineNo,mail);
94 sig = computeSignature(engineNo,mail);
97 System.out.println("Couldn't find the signature engine\n");
98 //sig = computeSignature(engineNo,curPart.getCleaned());
102 if (sig != null && sig.length > 0) {
103 String hash = engineNo + ":" + sig[curSigIndex];
104 printableSigs.add(hash);
106 /* we didn't produce a signature for the mail. */
110 return printableSigs;
118 private String computeSignature(int engineNo, String mail) {
121 return new String { this.sig4.computeSignature(mail) };
123 //TODO device and equivalent for this
124 //String cleanedButKeepHTML = Preprocessor.preprocess(mail,Preprocessor.ConfigParams.NO_DEHTML);
125 return this.sig8.computeSignature(cleanedButKeepHTML);