Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.tls;
  
  
Buffers input until the hash algorithm is determined.
 
     implements TlsHandshakeHash
 {
     protected static final int BUFFERING_HASH_LIMIT = 4;
 
     protected TlsContext context;
 
     private DigestInputBuffer buf;
     private Hashtable hashes;
     private Short prfHashAlgorithm;
 
     DeferredHash()
     {
         this. = new DigestInputBuffer();
         this. = new Hashtable();
         this. = null;
     }
 
     private DeferredHash(Short prfHashAlgorithmDigest prfHash)
     {
         this. = null;
         this. = new Hashtable();
         this. = prfHashAlgorithm;
         .put(prfHashAlgorithmprfHash);
     }
 
     public void init(TlsContext context)
     {
         this. = context;
     }
 
     {
         int prfAlgorithm = .getSecurityParameters().getPrfAlgorithm();
         if (prfAlgorithm == .)
         {
             CombinedHash legacyHash = new CombinedHash();
             legacyHash.init();
             .updateDigest(legacyHash);
             return legacyHash.notifyPRFDetermined();
         }
 
         this. = Shorts.valueOf(TlsUtils.getHashAlgorithmForPRFAlgorithm(prfAlgorithm));
 
 
         return this;
     }
 
     public void trackHashAlgorithm(short hashAlgorithm)
     {
         if ( == null)
         {
             throw new IllegalStateException("Too late to track more hash algorithms");
         }
 
         checkTrackingHash(Shorts.valueOf(hashAlgorithm));
     }
 
     public void sealHashAlgorithms()
     {
         checkStopBuffering();
     }
 
     public TlsHandshakeHash stopTracking()
     {
         Digest prfHash = TlsUtils.cloneHash(.shortValue(), (Digest).get());
         if ( != null)
         {
             .updateDigest(prfHash);
         }
         DeferredHash result = new DeferredHash(prfHash);
         result.init();
         return result;
     }
 
     public Digest forkPRFHash()
     {
         checkStopBuffering();
 
         if ( != null)
         {
             Digest prfHash = TlsUtils.createHash(.shortValue());
             .updateDigest(prfHash);
             return prfHash;
         }
 
         return TlsUtils.cloneHash(.shortValue(), (Digest).get());
    }
    public byte[] getFinalHash(short hashAlgorithm)
    {
        Digest d = (Digest).get(Shorts.valueOf(hashAlgorithm));
        if (d == null)
        {
            throw new IllegalStateException("HashAlgorithm " + hashAlgorithm + " is not being tracked");
        }
        d = TlsUtils.cloneHash(hashAlgorithmd);
        if ( != null)
        {
            .updateDigest(d);
        }
        byte[] bs = new byte[d.getDigestSize()];
        d.doFinal(bs, 0);
        return bs;
    }
    public String getAlgorithmName()
    {
        throw new IllegalStateException("Use fork() to get a definite Digest");
    }
    public int getDigestSize()
    {
        throw new IllegalStateException("Use fork() to get a definite Digest");
    }
    public void update(byte input)
    {
        if ( != null)
        {
            .write(input);
            return;
        }
        Enumeration e = .elements();
        while (e.hasMoreElements())
        {
            Digest hash = (Digest)e.nextElement();
            hash.update(input);
        }
    }
    public void update(byte[] inputint inOffint len)
    {
        if ( != null)
        {
            .write(inputinOfflen);
            return;
        }
        Enumeration e = .elements();
        while (e.hasMoreElements())
        {
            Digest hash = (Digest)e.nextElement();
            hash.update(inputinOfflen);
        }
    }
    public int doFinal(byte[] outputint outOff)
    {
        throw new IllegalStateException("Use fork() to get a definite Digest");
    }
    public void reset()
    {
        if ( != null)
        {
            .reset();
            return;
        }
        Enumeration e = .elements();
        while (e.hasMoreElements())
        {
            Digest hash = (Digest)e.nextElement();
            hash.reset();
        }
    }
    protected void checkStopBuffering()
    {
        if ( != null && .size() <= )
        {
            Enumeration e = .elements();
            while (e.hasMoreElements())
            {
                Digest hash = (Digest)e.nextElement();
                .updateDigest(hash);
            }
            this. = null;
        }
    }
    protected void checkTrackingHash(Short hashAlgorithm)
    {
        if (!.containsKey(hashAlgorithm))
        {
            Digest hash = TlsUtils.createHash(hashAlgorithm.shortValue());
            .put(hashAlgorithmhash);
        }
    }
New to GrepCode? Check out our FAQ X