src/share/classes/sun/security/provider/DigestBase.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File jdk Sdiff src/share/classes/sun/security/provider

src/share/classes/sun/security/provider/DigestBase.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105             throw new ArrayIndexOutOfBoundsException();
 106         }
 107         if (bytesProcessed < 0) {
 108             engineReset();
 109         }
 110         bytesProcessed += len;
 111         // if buffer is not empty, we need to fill it before proceeding
 112         if (bufOfs != 0) {
 113             int n = Math.min(len, blockSize - bufOfs);
 114             System.arraycopy(b, ofs, buffer, bufOfs, n);
 115             bufOfs += n;
 116             ofs += n;
 117             len -= n;
 118             if (bufOfs >= blockSize) {
 119                 // compress completed block now
 120                 implCompress(buffer, 0);
 121                 bufOfs = 0;
 122             }
 123         }
 124         // compress complete blocks
 125         while (len >= blockSize) {
 126             implCompress(b, ofs);
 127             len -= blockSize;
 128             ofs += blockSize;
 129         }
 130         // copy remainder to buffer
 131         if (len > 0) {
 132             System.arraycopy(b, ofs, buffer, 0, len);
 133             bufOfs = len;
 134         }
 135     }
 136 








 137     // reset this object. See JCA doc.
 138     protected final void engineReset() {
 139         if (bytesProcessed == 0) {
 140             // already reset, ignore
 141             return;
 142         }
 143         implReset();
 144         bufOfs = 0;
 145         bytesProcessed = 0;
 146     }
 147 
 148     // return the digest. See JCA doc.
 149     protected final byte[] engineDigest() {
 150         byte[] b = new byte[digestLength];
 151         try {
 152             engineDigest(b, 0, b.length);
 153         } catch (DigestException e) {
 154             throw (ProviderException)
 155                 new ProviderException("Internal error").initCause(e);
 156         }


   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105             throw new ArrayIndexOutOfBoundsException();
 106         }
 107         if (bytesProcessed < 0) {
 108             engineReset();
 109         }
 110         bytesProcessed += len;
 111         // if buffer is not empty, we need to fill it before proceeding
 112         if (bufOfs != 0) {
 113             int n = Math.min(len, blockSize - bufOfs);
 114             System.arraycopy(b, ofs, buffer, bufOfs, n);
 115             bufOfs += n;
 116             ofs += n;
 117             len -= n;
 118             if (bufOfs >= blockSize) {
 119                 // compress completed block now
 120                 implCompress(buffer, 0);
 121                 bufOfs = 0;
 122             }
 123         }
 124         // compress complete blocks
 125         if (len >= blockSize) {
 126             int limit = ofs + len;
 127             ofs = implCompressMultiBlock(b, ofs, limit - blockSize);
 128             len = limit - ofs;
 129         }
 130         // copy remainder to buffer
 131         if (len > 0) {
 132             System.arraycopy(b, ofs, buffer, 0, len);
 133             bufOfs = len;
 134         }
 135     }
 136 
 137     // compress complete blocks
 138     private int implCompressMultiBlock(byte[] b, int ofs, int limit) {
 139         for (; ofs <= limit; ofs += blockSize) {
 140             implCompress(b, ofs);
 141         }
 142         return ofs;
 143     }
 144 
 145     // reset this object. See JCA doc.
 146     protected final void engineReset() {
 147         if (bytesProcessed == 0) {
 148             // already reset, ignore
 149             return;
 150         }
 151         implReset();
 152         bufOfs = 0;
 153         bytesProcessed = 0;
 154     }
 155 
 156     // return the digest. See JCA doc.
 157     protected final byte[] engineDigest() {
 158         byte[] b = new byte[digestLength];
 159         try {
 160             engineDigest(b, 0, b.length);
 161         } catch (DigestException e) {
 162             throw (ProviderException)
 163                 new ProviderException("Internal error").initCause(e);
 164         }


src/share/classes/sun/security/provider/DigestBase.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File