99
100 /**
101 * Reads an AuthTime or AuthTimeWithHash object from a channel.
102 * @throws IOException if there is a format error
103 * @throws BufferUnderflowException if goes beyond the end
104 */
105 public static AuthTime readFrom(SeekableByteChannel chan)
106 throws IOException {
107 String client = readStringWithLength(chan);
108 String server = readStringWithLength(chan);
109 ByteBuffer bb = ByteBuffer.allocate(8);
110 chan.read(bb);
111 bb.order(ByteOrder.nativeOrder());
112 int cusec = bb.getInt(0);
113 int ctime = bb.getInt(4);
114 if (client.isEmpty()) {
115 StringTokenizer st = new StringTokenizer(server, " :");
116 if (st.countTokens() != 6) {
117 throw new IOException("Incorrect rcache style");
118 }
119 st.nextToken();
120 String hash = st.nextToken();
121 st.nextToken();
122 client = st.nextToken();
123 st.nextToken();
124 server = st.nextToken();
125 return new AuthTimeWithHash(
126 client, server, ctime, cusec, hash);
127 } else {
128 return new AuthTime(
129 client, server, ctime, cusec);
130 }
131 }
132
133 /**
134 * Encodes to be used in a dfl file
135 */
136 protected byte[] encode0(String cstring, String sstring) {
137 byte[] c = cstring.getBytes(StandardCharsets.UTF_8);;
138 byte[] s = sstring.getBytes(StandardCharsets.UTF_8);;
139 byte[] zero = new byte[1];
140 int len = 4 + c.length + 1 + 4 + s.length + 1 + 4 + 4;
141 ByteBuffer bb = ByteBuffer.allocate(len)
142 .order(ByteOrder.nativeOrder());
143 bb.putInt(c.length+1).put(c).put(zero)
144 .putInt(s.length+1).put(s).put(zero)
145 .putInt(cusec).putInt(ctime);
146 return bb.array();
|
99
100 /**
101 * Reads an AuthTime or AuthTimeWithHash object from a channel.
102 * @throws IOException if there is a format error
103 * @throws BufferUnderflowException if goes beyond the end
104 */
105 public static AuthTime readFrom(SeekableByteChannel chan)
106 throws IOException {
107 String client = readStringWithLength(chan);
108 String server = readStringWithLength(chan);
109 ByteBuffer bb = ByteBuffer.allocate(8);
110 chan.read(bb);
111 bb.order(ByteOrder.nativeOrder());
112 int cusec = bb.getInt(0);
113 int ctime = bb.getInt(4);
114 if (client.isEmpty()) {
115 StringTokenizer st = new StringTokenizer(server, " :");
116 if (st.countTokens() != 6) {
117 throw new IOException("Incorrect rcache style");
118 }
119 String hashAlg = st.nextToken();
120 String hash = st.nextToken();
121 st.nextToken();
122 client = st.nextToken();
123 st.nextToken();
124 server = st.nextToken();
125 return new AuthTimeWithHash(
126 client, server, ctime, cusec, hashAlg, hash);
127 } else {
128 return new AuthTime(
129 client, server, ctime, cusec);
130 }
131 }
132
133 /**
134 * Encodes to be used in a dfl file
135 */
136 protected byte[] encode0(String cstring, String sstring) {
137 byte[] c = cstring.getBytes(StandardCharsets.UTF_8);;
138 byte[] s = sstring.getBytes(StandardCharsets.UTF_8);;
139 byte[] zero = new byte[1];
140 int len = 4 + c.length + 1 + 4 + s.length + 1 + 4 + 4;
141 ByteBuffer bb = ByteBuffer.allocate(len)
142 .order(ByteOrder.nativeOrder());
143 bb.putInt(c.length+1).put(c).put(zero)
144 .putInt(s.length+1).put(s).put(zero)
145 .putInt(cusec).putInt(ctime);
146 return bb.array();
|