comparison app/src/main/java/ch/ethz/ssh2/DHGexParameters.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/DHGexParameters.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
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;
6
7 /**
8 * A <code>DHGexParameters</code> object can be used to specify parameters for
9 * the diffie-hellman group exchange.
10 * <p>
11 * Depending on which constructor is used, either the use of a
12 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code>
13 * can be forced.
14 *
15 * @see Connection#setDHGexParameters(DHGexParameters)
16 * @author Christian Plattner
17 * @version 2.50, 03/15/10
18 */
19
20 public class DHGexParameters {
21 private final int min_group_len;
22 private final int pref_group_len;
23 private final int max_group_len;
24
25 private static final int MIN_ALLOWED = 1024;
26 private static final int MAX_ALLOWED = 8192;
27
28 /**
29 * Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
30 * This is also the default used by the Connection class.
31 *
32 */
33 public DHGexParameters() {
34 this(1024, 1024, 4096);
35 }
36
37 /**
38 * This constructor can be used to force the sending of a
39 * <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
40 * Internally, the minimum and maximum group lengths will
41 * be set to zero.
42 *
43 * @param pref_group_len has to be &gt= 1024 and &lt;= 8192
44 */
45 public DHGexParameters(int pref_group_len) {
46 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
47 throw new IllegalArgumentException("pref_group_len out of range!");
48
49 this.pref_group_len = pref_group_len;
50 this.min_group_len = 0;
51 this.max_group_len = 0;
52 }
53
54 /**
55 * This constructor can be used to force the sending of a
56 * <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
57 * <p>
58 * Note: older OpenSSH servers don't understand this request, in which
59 * case you should use the {@link #DHGexParameters(int)} constructor.
60 * <p>
61 * All values have to be &gt= 1024 and &lt;= 8192. Furthermore,
62 * min_group_len &lt;= pref_group_len &lt;= max_group_len.
63 *
64 * @param min_group_len
65 * @param pref_group_len
66 * @param max_group_len
67 */
68 public DHGexParameters(int min_group_len, int pref_group_len, int max_group_len) {
69 if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
70 throw new IllegalArgumentException("min_group_len out of range!");
71
72 if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
73 throw new IllegalArgumentException("pref_group_len out of range!");
74
75 if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
76 throw new IllegalArgumentException("max_group_len out of range!");
77
78 if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len))
79 throw new IllegalArgumentException("pref_group_len is incompatible with min and max!");
80
81 if (max_group_len < min_group_len)
82 throw new IllegalArgumentException("max_group_len must not be smaller than min_group_len!");
83
84 this.min_group_len = min_group_len;
85 this.pref_group_len = pref_group_len;
86 this.max_group_len = max_group_len;
87 }
88
89 /**
90 * Get the maximum group length.
91 *
92 * @return the maximum group length, may be <code>zero</code> if
93 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
94 */
95 public int getMax_group_len() {
96 return max_group_len;
97 }
98
99 /**
100 * Get the minimum group length.
101 *
102 * @return minimum group length, may be <code>zero</code> if
103 * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
104 */
105 public int getMin_group_len() {
106 return min_group_len;
107 }
108
109 /**
110 * Get the preferred group length.
111 *
112 * @return the preferred group length
113 */
114 public int getPref_group_len() {
115 return pref_group_len;
116 }
117 }