src/java.base/share/classes/sun/security/provider/certpath/AdjacencyList.java
author weijun
Wed, 01 Aug 2018 13:35:08 +0800
changeset 51272 9d92ff04a29c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8208602: Cannot read PEM X.509 cert if there is whitespace after the header or footer Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * An AdjacencyList is used to store the history of certification paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * attempted in constructing a path from an initiator to a target. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * AdjacencyList is initialized with a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>List</code>s, where each sub-<code>List</code> contains objects of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * type <code>Vertex</code>. A <code>Vertex</code> describes one possible or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * actual step in the chain building process, and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>Certificate</code>. Specifically, a <code>Vertex</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * contains a <code>Certificate</code> and an index value referencing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * next sub-list in the process. If the index value is -1 then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>Vertex</code> doesn't continue the attempted build path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Attempted Paths:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <li>C1-&gt;C2-&gt;C3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>C1-&gt;C4-&gt;C5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>C1-&gt;C4-&gt;C6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <li>C1-&gt;C4-&gt;C7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <li>C1-&gt;C8-&gt;C9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>C1-&gt;C10-&gt;C11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * AdjacencyList structure:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <li>AL[0] = C1,1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li>AL[1] = C2,2   =&gt;C4,3   =&gt;C8,4     =&gt;C10,5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <li>AL[2] = C3,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <li>AL[3] = C5,-1  =&gt;C6,-1  =&gt;C7,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <li>AL[4] = C9,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>AL[5] = C11,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The iterator method returns objects of type <code>BuildStep</code>, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * objects of type <code>Vertex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * A <code>BuildStep</code> contains a <code>Vertex</code> and a result code,
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 12860
diff changeset
    67
 * accessible via getResult method. There are five result values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <code>POSSIBLE</code> denotes that the current step represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <code>Certificate</code> that the builder is considering at this point in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the build. <code>FOLLOW</code> denotes a <code>Certificate</code> (one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * those noted as <code>POSSIBLE</code>) that the builder is using to try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * extending the chain. <code>BACK</code> represents that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>FOLLOW</code> was incorrect, and is being removed from the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * There is exactly one <code>FOLLOW</code> for each <code>BACK</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * values <code>SUCCEED</code> and <code>FAIL</code> mean that we've come to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the end of the build process, and there will not be any more entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * the list.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
    78
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see sun.security.provider.certpath.BuildStep
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see sun.security.provider.certpath.Vertex
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
    81
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author  seth proctor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class AdjacencyList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // the actual set of steps the AdjacencyList represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private ArrayList<BuildStep> mStepList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // the original list, just for the toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private List<List<Vertex>> mOrigList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Constructs a new <code>AdjacencyList</code> based on the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <code>List</code>. See the example above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param list a <code>List</code> of <code>List</code>s of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *             <code>Vertex</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public AdjacencyList(List<List<Vertex>> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        mStepList = new ArrayList<BuildStep>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        mOrigList = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        buildList(list, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Gets an <code>Iterator</code> to iterate over the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <code>BuildStep</code>s in build-order. Any attempts to change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the list through the remove method will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return an <code>Iterator</code> over the <code>BuildStep</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public Iterator<BuildStep> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return Collections.unmodifiableList(mStepList).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Recursive, private method which actually builds the step list from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the given adjacency list. <code>Follow</code> is the parent BuildStep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * that we followed to get here, and if it's null, it means that we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * at the start.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private boolean buildList(List<List<Vertex>> theList, int index,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   124
                              BuildStep follow) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Each time this method is called, we're examining a new list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // from the global list. So, we have to start by getting the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // that contains the set of Vertexes we're considering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        List<Vertex> l = theList.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   131
        // we're interested in the case where all indexes are -1...
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   132
        boolean allNegOne = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   133
        // ...and in the case where every entry has a Throwable
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   134
        boolean allXcps = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   135
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   136
        for (Vertex v : l) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   137
            if (v.getIndex() != -1) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   138
                // count an empty list the same as an index of -1...this
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   139
                // is to patch a bug somewhere in the builder
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   140
                if (theList.get(v.getIndex()).size() != 0)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   141
                    allNegOne = false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   142
            } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   143
                if (v.getThrowable() == null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   144
                    allXcps = false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   145
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   146
            // every entry, regardless of the final use for it, is always
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   147
            // entered as a possible step before we take any actions
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   148
            mStepList.add(new BuildStep(v, BuildStep.POSSIBLE));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   149
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   150
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   151
        if (allNegOne) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   152
            // There are two cases that we could be looking at here. We
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   153
            // may need to back up, or the build may have succeeded at
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   154
            // this point. This is based on whether or not any
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   155
            // exceptions were found in the list.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   156
            if (allXcps) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   157
                // we need to go back...see if this is the last one
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   158
                if (follow == null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   159
                    mStepList.add(new BuildStep(null, BuildStep.FAIL));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   160
                else
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   161
                    mStepList.add(new BuildStep(follow.getVertex(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   162
                                                BuildStep.BACK));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   163
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   164
                return false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   165
            } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   166
                // we succeeded...now the only question is which is the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   167
                // successful step? If there's only one entry without
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   168
                // a throwable, then that's the successful step. Otherwise,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   169
                // we'll have to make some guesses...
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   170
                List<Vertex> possibles = new ArrayList<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   171
                for (Vertex v : l) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   172
                    if (v.getThrowable() == null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   173
                        possibles.add(v);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   174
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   175
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   176
                if (possibles.size() == 1) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   177
                    // real easy...we've found the final Vertex
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   178
                    mStepList.add(new BuildStep(possibles.get(0),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   179
                                                BuildStep.SUCCEED));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   180
                } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   181
                    // ok...at this point, there is more than one Cert
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   182
                    // which might be the succeed step...how do we know
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   183
                    // which it is? I'm going to assume that our builder
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   184
                    // algorithm is good enough to know which is the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   185
                    // correct one, and put it first...but a FIXME goes
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   186
                    // here anyway, and we should be comparing to the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   187
                    // target/initiator Cert...
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   188
                    mStepList.add(new BuildStep(possibles.get(0),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   189
                                                BuildStep.SUCCEED));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   190
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   191
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   192
                return true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   193
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   194
        } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   195
            // There's at least one thing that we can try before we give
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   196
            // up and go back. Run through the list now, and enter a new
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   197
            // BuildStep for each path that we try to follow. If none of
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   198
            // the paths we try produce a successful end, we're going to
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   199
            // have to back out ourselves.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   200
            boolean success = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            for (Vertex v : l) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   203
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   204
                // Note that we'll only find a SUCCEED case when we're
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   205
                // looking at the last possible path, so we don't need to
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   206
                // consider success in the while loop
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   207
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (v.getIndex() != -1) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   209
                    if (theList.get(v.getIndex()).size() != 0) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   210
                        // If the entry we're looking at doesn't have an
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   211
                        // index of -1, and doesn't lead to an empty list,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   212
                        // then it's something we follow!
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   213
                        BuildStep bs = new BuildStep(v, BuildStep.FOLLOW);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   214
                        mStepList.add(bs);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   215
                        success = buildList(theList, v.getIndex(), bs);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   216
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   220
            if (success) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   221
                // We're already finished!
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   222
                return true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   223
            } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   224
                // We failed, and we've exhausted all the paths that we
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   225
                // could take. The only choice is to back ourselves out.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   226
                if (follow == null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   227
                    mStepList.add(new BuildStep(null, BuildStep.FAIL));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   228
                else
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   229
                    mStepList.add(new BuildStep(follow.getVertex(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   230
                                                BuildStep.BACK));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   232
                return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Prints out a string representation of this AdjacencyList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return String representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   242
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public String toString() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   244
        StringBuilder sb = new StringBuilder("[\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        for (List<Vertex> l : mOrigList) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   248
            sb.append("LinkedList[").append(i++).append("]:\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            for (Vertex step : l) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   251
                sb.append(step.toString()).append("\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   254
        sb.append("]\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 5506
diff changeset
   256
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
}