jdk/src/java.base/share/classes/sun/security/util/ManifestDigester.java
author darcy
Thu, 23 Apr 2015 18:51:18 -0700
changeset 30033 b9c86c17164a
parent 25859 3317bb8137f4
child 30374 2abaf49910ea
permissions -rw-r--r--
8078468: Update security libraries to use diamond with anonymous classes Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3048
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3048
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3048
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3048
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3048
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class is used to compute digests on sections of the Manifest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class ManifestDigester {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public static final String MF_MAIN_ATTRS = "Manifest-Main-Attributes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /** the raw bytes of the manifest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private byte rawBytes[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /** the offset/length pair for a section */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private HashMap<String, Entry> entries; // key is a UTF-8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /** state returned by findSection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static class Position {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        int endOfFirstLine; // not including newline character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        int endOfSection; // end of section, not including the blank line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                          // between sections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        int startOfNext;  // the start of the next section
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * find a section in the manifest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param offset should point to the starting offset with in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * raw bytes of the next section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @pos set by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @returns false if end of bytes has been reached, otherwise returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *          true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    65
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean findSection(int offset, Position pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        int i = offset, len = rawBytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        int last = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        int next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        boolean allBlank = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        pos.endOfFirstLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        while (i < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            byte b = rawBytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            switch(b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                if (pos.endOfFirstLine == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    pos.endOfFirstLine = i-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                if ((i < len) &&  (rawBytes[i+1] == '\n'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    i++;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    83
                /* fall through */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                if (pos.endOfFirstLine == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    pos.endOfFirstLine = i-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                if (allBlank || (i == len-1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    if (i == len-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        pos.endOfSection = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        pos.endOfSection = last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    pos.startOfNext = i+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    // start of a new line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    last = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    allBlank = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                allBlank = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public ManifestDigester(byte bytes[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        rawBytes = bytes;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   113
        entries = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Position pos = new Position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (!findSection(0, pos))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return; // XXX: exception?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // create an entry for main attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        entries.put(MF_MAIN_ATTRS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                new Entry(0, pos.endOfSection + 1, pos.startOfNext, rawBytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        int start = pos.startOfNext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        while(findSection(start, pos)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            int len = pos.endOfFirstLine-start+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            int sectionLen = pos.endOfSection-start+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            int sectionLenWithBlank = pos.startOfNext-start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (len > 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (isNameAttr(bytes, start)) {
3048
5c169b3218a5 6833839: RFE: improve ManifestDigester by instantiating StringBuilder constructor w/ initial value
mullan
parents: 2
diff changeset
   134
                    StringBuilder nameBuf = new StringBuilder(sectionLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        nameBuf.append(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            new String(bytes, start+6, len-6, "UTF8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        int i = start + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        if ((i-start) < sectionLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                            if (bytes[i] == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                i += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                i += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        while ((i-start) < sectionLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                            if (bytes[i++] == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                // name is wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                int wrapStart = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                while (((i-start) < sectionLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                        && (bytes[i++] != '\n'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                    if (bytes[i-1] != '\n')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                        return; // XXX: exception?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                    int wrapLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                    if (bytes[i-2] == '\r')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                        wrapLen = i-wrapStart-2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                        wrapLen = i-wrapStart-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                            nameBuf.append(new String(bytes, wrapStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                                      wrapLen, "UTF8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        entries.put(nameBuf.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                            new Entry(start, sectionLen, sectionLenWithBlank,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                rawBytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                            "UTF8 not available on platform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            start = pos.startOfNext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private boolean isNameAttr(byte bytes[], int start)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return ((bytes[start] == 'N') || (bytes[start] == 'n')) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
               ((bytes[start+1] == 'a') || (bytes[start+1] == 'A')) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
               ((bytes[start+2] == 'm') || (bytes[start+2] == 'M')) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
               ((bytes[start+3] == 'e') || (bytes[start+3] == 'E')) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
               (bytes[start+4] == ':') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
               (bytes[start+5] == ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static class Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        int lengthWithBlankLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        byte[] rawBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        boolean oldStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public Entry(int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                     int lengthWithBlankLine, byte[] rawBytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            this.length = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            this.lengthWithBlankLine = lengthWithBlankLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            this.rawBytes = rawBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        public byte[] digest(MessageDigest md)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            md.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                doOldStyle(md,rawBytes, offset, lengthWithBlankLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                md.update(rawBytes, offset, lengthWithBlankLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        private void doOldStyle(MessageDigest md,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                byte[] bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                int offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // this is too gross to even document, but here goes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // the 1.1 jar verification code ignored spaces at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            // end of lines when calculating digests, so that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // what this code does. It only gets called if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // are parsing a 1.1 signed signature file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            int i = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            int start = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            int max = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            int prev = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            while(i <max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if ((bytes[i] == '\r') && (prev == ' ')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    md.update(bytes, start, i-start-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    start = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                prev = bytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            md.update(bytes, start, i-start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        /** Netscape doesn't include the new line. Intel and JavaSoft do */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        public byte[] digestWorkaround(MessageDigest md)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            md.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            md.update(rawBytes, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Entry get(String name, boolean oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        Entry e = entries.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (e != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            e.oldStyle = oldStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public byte[] manifestDigest(MessageDigest md)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            md.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            md.update(rawBytes, 0, rawBytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}