本文整理汇总了Java中org.bouncycastle.util.IPAddress.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddress.isValid方法的具体用法?Java IPAddress.isValid怎么用?Java IPAddress.isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.IPAddress
的用法示例。
在下文中一共展示了IPAddress.isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIP
import org.bouncycastle.util.IPAddress; //导入方法依赖的package包/类
private void testIP(String[] valid, String[] invalid)
{
for (int i = 0; i < valid.length; i++)
{
if (!IPAddress.isValid(valid[i]))
{
fail("Valid input string not accepted: " + valid[i] + ".");
}
}
for (int i = 0; i < invalid.length; i++)
{
if (IPAddress.isValid(invalid[i]))
{
fail("Invalid input string accepted: " + invalid[i] + ".");
}
}
}
示例2: GeneralName
import org.bouncycastle.util.IPAddress; //导入方法依赖的package包/类
/**
* Create a GeneralName for the given tag from the passed in String.
* <p>
* This constructor can handle:
* <ul>
* <li>rfc822Name
* <li>iPAddress
* <li>directoryName
* <li>dNSName
* <li>uniformResourceIdentifier
* <li>registeredID
* </ul>
* For x400Address, otherName and ediPartyName there is no common string
* format defined.
* <p>
* Note: A directory name can be encoded in different ways into a byte
* representation. Be aware of this if the byte representation is used for
* comparing results.
*
* @param tag tag number
* @param name string representation of name
* @throws IllegalArgumentException if the string encoding is not correct or * not supported.
*/
public GeneralName(
int tag,
String name)
{
this.tag = tag;
if (tag == rfc822Name || tag == dNSName || tag == uniformResourceIdentifier)
{
this.obj = new DERIA5String(name);
}
else if (tag == registeredID)
{
this.obj = new DERObjectIdentifier(name);
}
else if (tag == directoryName)
{
this.obj = new X509Name(name);
}
else if (tag == iPAddress)
{
if (IPAddress.isValid(name))
{
this.obj = new DEROctetString(Strings.toUTF8ByteArray(name));
}
else
{
throw new IllegalArgumentException("IP Address is invalid");
}
}
else
{
throw new IllegalArgumentException("can't process String for tag: " + tag);
}
}