View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.sftp;
18  
19  import java.io.File;
20  
21  
22  /**
23   * Structure for an identity.
24   *
25   * @since 2.1
26   */
27  public class IdentityInfo
28  {
29      private final File privateKey;
30      private final File publicKey;
31      private final byte[] passPhrase;
32  
33      /**
34       * Constructs an identity info with private key.
35       * <p>
36       * The key is not passphrase protected.
37       * <p>
38       * We use java.io.File because JSch cannot deal with VFS FileObjects.
39       *
40       * @param privateKey The file with the private key
41       * @since 2.1
42       */
43      public IdentityInfo(final File privateKey)
44      {
45          this(privateKey, null, null);
46      }
47  
48      /**
49       * Constructs an identity info with private key and its passphrase.
50       * <p>
51       * We use java.io.File because JSch cannot deal with VFS FileObjects.
52       *
53       * @param privateKey The file with the private key
54       * @param passPhrase The passphrase to decrypt the private key (can be {@code null} if no passphrase is used)
55       * @since 2.1
56       */
57      public IdentityInfo(final File privateKey, final byte[] passPhrase)
58      {
59          this(privateKey, null, passPhrase);
60      }
61  
62      /**
63       * Constructs an identity info with private and public key and passphrase for the private key.
64       * <p>
65       * We use java.io.File because JSch cannot deal with VFS FileObjects.
66       *
67       * @param privateKey The file with the private key
68       * @param publicKey The public key part used for connections with exchange of certificates (can be {@code null})
69       * @param passPhrase The passphrase to decrypt the private key (can be {@code null} if no passphrase is used)
70       * @since 2.1
71       */
72      public IdentityInfo(final File privateKey, final File publicKey, final byte[] passPhrase)
73      {
74          this.privateKey = privateKey;
75          this.publicKey = publicKey;
76          this.passPhrase = passPhrase;
77      }
78  
79      /**
80       * Get the file with the private key.
81       *
82       * @return the file
83       * @since 2.1
84       */
85      public File getPrivateKey()
86      {
87          return privateKey;
88      }
89  
90      /**
91       * Get the file with the public key.
92       *
93       * @return the file
94       * @since 2.1
95       */
96      public File getPublicKey()
97      {
98          return publicKey;
99      }
100 
101     /**
102      * Get the passphrase of the private key.
103      *
104      * @return the passphrase
105      * @since 2.1
106      */
107     public byte[] getPassPhrase()
108     {
109         return passPhrase;
110     }
111 }