Coverage Summary for Class: AuthResponseMessageV4 (org.ethereum.net.rlpx)

Class Class, % Method, % Line, %
AuthResponseMessageV4 0% (0/1) 0% (0/4) 0% (0/21)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.net.rlpx; 21  22 import org.bouncycastle.math.ec.ECPoint; 23 import org.ethereum.crypto.ECKey; 24 import org.ethereum.util.ByteUtil; 25 import org.ethereum.util.RLP; 26 import org.ethereum.util.RLPList; 27  28 /** 29  * Auth Response message defined by EIP-8 30  * 31  * @author mkalinin 32  * @since 17.02.2016 33  */ 34 public class AuthResponseMessageV4 { 35  36  ECPoint ephemeralPublicKey; // 64 bytes - uncompressed and no type byte 37  byte[] nonce; // 32 bytes 38  int version = 4; // 4 bytes 39  40  static AuthResponseMessageV4 decode(byte[] wire) { 41  42  AuthResponseMessageV4 message = new AuthResponseMessageV4(); 43  44  RLPList params = (RLPList) RLP.decode2OneItem(wire, 0); 45  46  byte[] pubKeyBytes = params.get(0).getRLPData(); 47  48  byte[] bytes = new byte[65]; 49  System.arraycopy(pubKeyBytes, 0, bytes, 1, 64); 50  bytes[0] = 0x04; // uncompressed 51  message.ephemeralPublicKey = ECKey.CURVE.getCurve().decodePoint(bytes); 52  53  message.nonce = params.get(1).getRLPData(); 54  55  byte[] versionBytes = params.get(2).getRLPData(); 56  message.version = ByteUtil.byteArrayToInt(versionBytes); 57  58  return message; 59  } 60  61  public byte[] encode() { 62  63  byte[] publicKey = new byte[64]; 64  System.arraycopy(ephemeralPublicKey.getEncoded(false), 1, publicKey, 0, publicKey.length); 65  66  byte[] publicBytes = RLP.encode(publicKey); 67  byte[] nonceBytes = RLP.encode(nonce); 68  byte[] versionBytes = RLP.encodeInt(version); 69  70  return RLP.encodeList(publicBytes, nonceBytes, versionBytes); 71  } 72  73  @Override 74  public String toString() { 75  return "AuthResponseMessage{" + 76  "\n ephemeralPublicKey=" + ephemeralPublicKey + 77  "\n nonce=" + ByteUtil.toHexString(nonce) + 78  "\n version=" + version + 79  '}'; 80  } 81 }