]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/frontends/android/app/src/main/java/org/strongswan/android/logic/imc/attributes/InstalledPackagesAttribute.java
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / logic / imc / attributes / InstalledPackagesAttribute.java
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2012 Christoph Buehler
4 * Copyright (C) 2012 Patrick Loetscher
5 *
6 * Copyright (C) secunet Security Networks AG
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 package org.strongswan.android.logic.imc.attributes;
20
21 import java.util.LinkedList;
22
23 import org.strongswan.android.utils.BufferedByteWriter;
24
25 import android.util.Pair;
26
27 /**
28 * PA-TNC Installed Packages attribute (see section 4.2.7 of RFC 5792)
29 *
30 * 1 2 3
31 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Reserved | Package Count |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Pkg Name Len | Package Name (Variable Length) |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Version Len | Package Version Number (Variable Length) |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 */
40 public class InstalledPackagesAttribute implements Attribute
41 {
42 private final short RESERVED = 0;
43 private final LinkedList<Pair<String, String>> mPackages = new LinkedList<Pair<String, String>>();
44
45 /**
46 * Add an installed package to this attribute.
47 * @param name name of the package
48 * @param version version number of the package
49 */
50 public void addPackage(String name, String version)
51 {
52 mPackages.add(new Pair<String, String>(name, version));
53 }
54
55 @Override
56 public byte[] getEncoding()
57 {
58 BufferedByteWriter writer = new BufferedByteWriter();
59 writer.put16(RESERVED);
60 writer.put16((short)mPackages.size());
61 for (Pair<String, String> pair : mPackages)
62 {
63 writer.putLen8(pair.first.getBytes());
64 writer.putLen8(pair.second.getBytes());
65 }
66 return writer.toByteArray();
67 }
68 }