1 /*
2 * Copyright 2024–2026 Michael Osipov
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 package net.sf.michaelo.tomcat.pac;
17
18 import java.nio.charset.StandardCharsets;
19 import java.util.Objects;
20
21 /**
22 * A class representing the <a href=
23 * "https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-pac/e465cb27-4bc1-4173-8be0-b5fd64dc9ff7">{@code PAC_CLIENT_INFO}</a>
24 * structure from MS-PAC.
25 */
26 public class PacClientInfo {
27
28 private final String name;
29
30 /**
31 * Parses a PAC client info object from a byte array.
32 *
33 * @param infoBytes PAC client info structure encoded as bytes
34 * @throws NullPointerException if {@code infoBytes} is null
35 * @throws IllegalArgumentException if {@code infoBytes} is empty
36 */
37 public PacClientInfo(byte[] infoBytes) {
38 Objects.requireNonNull(infoBytes, "infoBytes cannot be null");
39 if (infoBytes.length == 0) throw new IllegalArgumentException("infoBytes cannot be empty");
40
41 PacDataBuffer buf = new PacDataBuffer(infoBytes);
42
43 // ClientId
44 buf.skip(8);
45 // NameLength
46 int nameLength = buf.getUnsignedShort();
47 // Name
48 byte[] dst = new byte[nameLength];
49 buf.get(dst);
50 this.name = new String(dst, StandardCharsets.UTF_16LE);
51 }
52
53 public String getName() {
54 return name;
55 }
56 }