1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package libcore.tlswire.record;
18
19import libcore.tlswire.util.TlsProtocolVersion;
20import java.io.DataInput;
21import java.io.IOException;
22
23/**
24 * TLS Record Protocol record from TLS 1.2 RFC 5246.
25 */
26public class TlsRecord {
27    public int type;
28    public TlsProtocolVersion version;
29    public byte[] fragment;
30
31    public static TlsRecord read(DataInput in) throws IOException {
32        TlsRecord result = new TlsRecord();
33        result.type = in.readUnsignedByte();
34        result.version = TlsProtocolVersion.read(in);
35        int fragmentLength = in.readUnsignedShort();
36        result.fragment = new byte[fragmentLength];
37        in.readFully(result.fragment);
38        return result;
39    }
40}
41