diff options
author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-12-19 01:21:06 +0000 |
---|---|---|
committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-12-19 01:21:06 +0000 |
commit | eb7f0a53d54b6bffa8f761d91da3e7790337e529 (patch) | |
tree | 910cacdf172f69636faa940cb696b75333a092b2 /java | |
parent | 810346d1068644561c0bfd0da3dd61f48a23b8a0 (diff) | |
download | ATCD-eb7f0a53d54b6bffa8f761d91da3e7790337e529.tar.gz |
This currently just contains the encoding function for the basic
password encryption specified in the HTTP v1.1 RFC. (It's used by
JAWS during the PUT command authentication.)
Diffstat (limited to 'java')
-rw-r--r-- | java/src/HTTPHelper.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/java/src/HTTPHelper.java b/java/src/HTTPHelper.java new file mode 100644 index 00000000000..cfb5e01876f --- /dev/null +++ b/java/src/HTTPHelper.java @@ -0,0 +1,85 @@ +package JACE.Connection; + +import java.lang.*; +import JACE.OS.*; +// Collection of various methods that have to do with HTTP + +public class HTTPHelper +{ + // Encoding and decoding yadda + public static String Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + // Basic encoding used in the HTTP 1.1 RFC. This doesn't + // put the string "Basic " at the beginning of the return + // string. Adapted from James' JAWS HTTP_Helpers code. + // Returns null on error. + public static String EncodeBase64 (String secret) + { + StringBuffer output = new StringBuffer(); + + // Index of the input string + int inidx = 0; + + // character value + int c; + + int char_count = 0; + int bits = 0; + boolean error = false; + + while (inidx < secret.length()) + { + c = secret.charAt(inidx++); + + // This will mess up internationalization. I wonder if it is really + // necessary for HTTP? + if (c > 255) + { + ACE.DEBUG ("encountered char > 255 (decimal %d): " + c); + error = true; + break; + } + + bits += c; + char_count++; + + if (char_count == 3) + { + output.append(HTTPHelper.Alphabet.charAt(bits >> 18)); + output.append(HTTPHelper.Alphabet.charAt((bits >> 12) & 0x3f)); + output.append(HTTPHelper.Alphabet.charAt((bits >> 6) & 0x3f)); + output.append(HTTPHelper.Alphabet.charAt(bits & 0x3f)); + + bits = 0; + char_count = 0; + } + else + bits <<= 8; + } + + if (!error) + { + if (char_count != 0) + { + bits <<= 16 - (8 * char_count); + output.append(HTTPHelper.Alphabet.charAt(bits >> 18)); + output.append(HTTPHelper.Alphabet.charAt((bits >> 12) & 0x3f)); + + if (char_count == 1) + { + output.append("=="); + } + else + { + output.append(HTTPHelper.Alphabet.charAt((bits >> 6) & 0x3f)); + output.append('='); + } + } + + return output.toString(); + } + + // Returns null on error + return null; + } +}; |