Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/LocalSeqNumber.java
41161 views
/*1* Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*27* (C) Copyright IBM Corp. 1999 All Rights Reserved.28* Copyright 1997 The Open Group Research Institute. All rights reserved.29*/3031package sun.security.krb5.internal;3233import sun.security.krb5.Confounder;3435public class LocalSeqNumber implements SeqNumber {36private int lastSeqNumber;3738public LocalSeqNumber() {39randInit();40}4142public LocalSeqNumber(int start) {43init(start);44}4546public LocalSeqNumber(Integer start) {47init(start.intValue());48}4950public synchronized void randInit() {51/*52* Sequence numbers fall in the range 0 through 2^32 - 1 and wrap53* to zero following the value 2^32 - 1.54* Previous implementations used signed sequence numbers.55* Workaround implementation incompatibilities by not generating56* initial sequence numbers greater than 2^30, as done57* in MIT distribution.58*/59// get the random confounder60byte[] data = Confounder.bytes(4);61data[0] = (byte)(data[0] & 0x3f);62int result = ((data[3] & 0xff) |63((data[2] & 0xff) << 8) |64((data[1] & 0xff) << 16) |65((data[0] & 0xff) << 24));66if (result == 0) {67result = 1;68}69lastSeqNumber = result;70}7172public synchronized void init(int start) {73lastSeqNumber = start;74}7576public synchronized int current() {77return lastSeqNumber;78}7980public synchronized int next() {81return lastSeqNumber + 1;82}8384public synchronized int step() {85return ++lastSeqNumber;86}8788}899091