Home | History | Annotate | Download | only in packets
      1 /*
      2  * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
      3  * Please refer to the LICENSE.txt for licensing details.
      4  */
      5 package ch.ethz.ssh2.packets;
      6 
      7 import java.io.IOException;
      8 
      9 /**
     10  * PacketUserauthBanner.
     11  *
     12  * @author Christian Plattner
     13  * @version 2.50, 03/15/10
     14  */
     15 public class PacketUserauthBanner
     16 {
     17 	byte[] payload;
     18 
     19 	String message;
     20 	String language;
     21 
     22 	public PacketUserauthBanner(String message, String language)
     23 	{
     24 		this.message = message;
     25 		this.language = language;
     26 	}
     27 
     28 	public String getBanner()
     29 	{
     30 		return message;
     31 	}
     32 
     33 	public PacketUserauthBanner(byte payload[], int off, int len) throws IOException
     34 	{
     35 		this.payload = new byte[len];
     36 		System.arraycopy(payload, off, this.payload, 0, len);
     37 
     38 		TypesReader tr = new TypesReader(payload, off, len);
     39 
     40 		int packet_type = tr.readByte();
     41 
     42 		if (packet_type != Packets.SSH_MSG_USERAUTH_BANNER)
     43 			throw new IOException("This is not a SSH_MSG_USERAUTH_BANNER! (" + packet_type + ")");
     44 
     45 		message = tr.readString("UTF-8");
     46 		language = tr.readString();
     47 
     48 		if (tr.remain() != 0)
     49 			throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
     50 	}
     51 
     52 	public byte[] getPayload()
     53 	{
     54 		if (payload == null)
     55 		{
     56 			TypesWriter tw = new TypesWriter();
     57 			tw.writeByte(Packets.SSH_MSG_USERAUTH_BANNER);
     58 			tw.writeString(message);
     59 			tw.writeString(language);
     60 			payload = tw.getBytes();
     61 		}
     62 		return payload;
     63 	}
     64 }
     65