1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.pkix.params.x509certificate.extension

File X509Rfc822Name.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
16
6
1
106
50
8
0.5
2.67
6
1.33

Classes

Class Line # Actions
X509Rfc822Name 35 16 0% 8 3
0.87587.5%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.pkix.params.x509certificate.extension;
21   
22    import javax.mail.internet.AddressException;
23    import javax.mail.internet.InternetAddress;
24   
25    import org.bouncycastle.asn1.DERIA5String;
26    import org.bouncycastle.asn1.x509.GeneralName;
27    import org.xwiki.crypto.pkix.internal.extension.BcGeneralName;
28   
29    /**
30    * Email address general name.
31    *
32    * @version $Id: dd0850adab58f8eafab002a65fab75e8267257c8 $
33    * @since 5.4
34    */
 
35    public class X509Rfc822Name implements X509StringGeneralName, BcGeneralName
36    {
37    private final String str;
38   
39    private final InternetAddress addr;
40   
41    /**
42    * Constructs a RFC 822 general name by parsing the given string.
43    *
44    * @param address the address compliant with RFC 822.
45    */
 
46  4 toggle public X509Rfc822Name(String address)
47    {
48  4 String newStr = null;
49  4 InternetAddress newAddr = null;
50   
51  4 try {
52  4 newAddr = new InternetAddress(address);
53  4 newStr = newAddr.getAddress();
54    } catch (AddressException e) {
55  0 newStr = address;
56    }
57   
58  4 this.str = newStr;
59  4 this.addr = newAddr;
60    }
61   
62    /**
63    * Constructs a RFC 822 general name from an internet address.
64    *
65    * @param address the address compliant with RFC 822.
66    */
 
67  1 toggle public X509Rfc822Name(InternetAddress address)
68    {
69  1 this.addr = address;
70  1 this.str = address.getAddress();
71    }
72   
73    /**
74    * Create a new instance from a Bouncy Castle general name.
75    *
76    * @param name the Bouncy Castle general name.
77    */
 
78  2 toggle public X509Rfc822Name(GeneralName name)
79    {
80  2 this(DERIA5String.getInstance(name.getName()).getString());
81   
82  2 if (name.getTagNo() != GeneralName.rfc822Name) {
83  0 throw new IllegalArgumentException("Incompatible general name: " + name.getTagNo());
84    }
85    }
86   
87    /**
88    * @return the internet address represented by the general name, or null if the address could not be parsed.
89    */
 
90  2 toggle public InternetAddress getAddress()
91    {
92  2 return this.addr;
93    }
94   
 
95  2 toggle @Override
96    public String getName()
97    {
98  2 return this.str;
99    }
100   
 
101  3 toggle @Override
102    public GeneralName getGeneralName()
103    {
104  3 return new GeneralName(GeneralName.rfc822Name, this.str);
105    }
106    }