Changeset 6c7e913


Ignore:
Timestamp:
Feb 17, 2011 4:35:30 PM (9 years ago)
Author:
dev <dev@…>
Branches:
master
Children:
edb976b, f9b2c771
Parents:
b208295
Message:

fixed formatting

Location:
core/java/src/net/i2p/client/datagram
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/client/datagram/I2PDatagramDissector.java

    rb208295 r6c7e913  
    6464        ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
    6565        byte[] rxTrimmedPayload;
    66 
    67                 // set invalid(very important!)
    68                 this.valid = false;
    69 
     66       
     67        // set invalid(very important!)
     68        this.valid = false;
     69       
    7070        try {
    7171            rxDest = new Destination();
    7272            rxSign = new Signature();
    73 
    74                         // read destination
     73           
     74            // read destination
    7575            rxDest.readBytes(dgStream);
    76 
    77                         // read signature
     76           
     77            // read signature
    7878            rxSign.readBytes(dgStream);
    79 
    80                         // read payload
     79           
     80            // read payload
    8181            rxPayloadLen = dgStream.read(rxPayload);
    82                        
    83                         // calculate the hash of the payload
     82           
     83            // calculate the hash of the payload
    8484            this.rxHash = hashGen.calculateHash(rxPayload, 0, rxPayloadLen);
    85                         assert this.hashGen.calculateHash(this.extractPayload()).equals(this.rxHash);
     85            assert this.hashGen.calculateHash(this.extractPayload()).equals(this.rxHash);
    8686        } catch (IOException e) {
    8787            _log.error("Caught IOException - INCONSISTENT STATE!", e);
    8888        } catch(AssertionError e) {
    89                         _log.error("Assertion failed!", e);
    90                 }
    91 
     89            _log.error("Assertion failed!", e);
     90        }
     91       
    9292        //_log.debug("Datagram payload size: " + rxPayloadLen + "; content:\n"
    9393        //           + HexDump.dump(rxPayload, 0, rxPayloadLen));
    9494    }
    95 
     95   
    9696    /**
    9797     * Get the payload carried by an I2P repliable datagram (previously loaded
     
    107107        return this.extractPayload();
    108108    }
    109 
     109   
    110110    /**
    111111     * Get the sender of an I2P repliable datagram (previously loaded with the
     
    119119        this.verifySignature();
    120120       
    121                 return this.extractSender();
    122     }
    123 
    124         /**
    125         * Extract the hash of the payload of an I2P repliable datagram (previously
    126         * loaded with the loadI2PDatagram() method), verifying the datagram
    127         * signature.
    128         * @return The hash of the payload of the I2P repliable datagram
    129         * @throws I2PInvalidDatagramException if the signature verification fails
    130         */
    131         public Hash getHash() throws I2PInvalidDatagramException {
    132                 // make sure it has a valid signature
    133                 this.verifySignature();
    134 
    135                 return this.extractHash();
    136         }
    137 
     121        return this.extractSender();
     122    }
     123   
     124    /**
     125    * Extract the hash of the payload of an I2P repliable datagram (previously
     126    * loaded with the loadI2PDatagram() method), verifying the datagram
     127    * signature.
     128    * @return The hash of the payload of the I2P repliable datagram
     129    * @throws I2PInvalidDatagramException if the signature verification fails
     130    */
     131    public Hash getHash() throws I2PInvalidDatagramException {
     132        // make sure it has a valid signature
     133        this.verifySignature();
     134       
     135        return this.extractHash();
     136    }
     137   
    138138    /**
    139139     * Extract the payload carried by an I2P repliable datagram (previously
     
    146146        byte[] retPayload = new byte[this.rxPayloadLen];
    147147        System.arraycopy(this.rxPayload, 0, retPayload, 0, this.rxPayloadLen);
    148 
     148       
    149149        return retPayload;
    150150    }
    151 
     151   
    152152    /**
    153153     * Extract the sender of an I2P repliable datagram (previously loaded with
     
    169169        return retDest;
    170170    }
    171 
    172         /**
    173         * Extract the hash of the payload of an I2P repliable datagram (previously
    174         * loaded with the loadI2PDatagram() method), without verifying the datagram
    175         * signature.
    176         * @return The hash of the payload of the I2P repliable datagram
    177         */
    178         public Hash extractHash() {
    179                 return this.rxHash;
    180         }
     171   
     172    /**
     173    * Extract the hash of the payload of an I2P repliable datagram (previously
     174    * loaded with the loadI2PDatagram() method), without verifying the datagram
     175    * signature.
     176    * @return The hash of the payload of the I2P repliable datagram
     177    */
     178    public Hash extractHash() {
     179        return this.rxHash;
     180    }
    181181   
    182182    /**
    183183     * Verify the signature of this datagram (previously loaded with the
    184184     * loadI2PDatagram() method)
    185         * @throws I2PInvalidDatagramException if the signature is invalid
     185    * @throws I2PInvalidDatagramException if the signature is invalid
    186186     */
    187187    public void verifySignature() throws I2PInvalidDatagramException {
     
    192192        if (rxSign == null || rxSign.getData() == null || rxDest == null || rxDest.getSigningPublicKey() == null)
    193193            throw new I2PInvalidDatagramException("Datagram not yet read");
    194 
     194       
    195195        // now validate
    196196        if (!this.dsaEng.verifySignature(rxSign, rxHash.getData(), rxDest.getSigningPublicKey()))
  • core/java/src/net/i2p/client/datagram/I2PDatagramMaker.java

    rb208295 r6c7e913  
    7171        try {
    7272            sxDGram.write(sxDestBytes);
    73        
     73           
    7474            dsaEng.sign(hashGen.calculateHash(payload).toByteArray(),
    7575                        sxPrivKey).writeBytes(sxDGram);
    76 
     76           
    7777            sxDGram.write(payload);
    78 
     78           
    7979            return sxDGram.toByteArray();
    8080        } catch (IOException e) {
Note: See TracChangeset for help on using the changeset viewer.