![JAR search and dependency download from the Maven repository](/logo.png)
org.bouncycastle.bcpg.sig.RegularExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpg-jdk15to18 Show documentation
Show all versions of bcpg-jdk15to18 Show documentation
The Bouncy Castle Java API for handling the OpenPGP protocol. This jar contains the OpenPGP API for JDK 1.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
The newest version!
package org.bouncycastle.bcpg.sig;
import org.bouncycastle.bcpg.SignatureSubpacket;
import org.bouncycastle.bcpg.SignatureSubpacketTags;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Strings;
/**
* Signature Subpacket containing a regular expression limiting the scope of the signature.
* Note: the RFC says the byte encoding is to be null terminated.
*
* @see
* RFC4880 - Regular Expression
* @see
* RFC9580 - Regular Expression
*/
public class RegularExpression
extends SignatureSubpacket
{
public RegularExpression(
boolean critical,
boolean isLongLength,
byte[] data)
{
super(SignatureSubpacketTags.REG_EXP, critical, isLongLength, data);
if (data[data.length - 1] != 0)
{
throw new IllegalArgumentException("data in regex missing null termination");
}
}
public RegularExpression(
boolean critical,
String regex)
{
super(
SignatureSubpacketTags.REG_EXP,
critical,
false,
toNullTerminatedUTF8ByteArray(regex));
}
public String getRegex()
{
// last byte is null terminator
return Strings.fromUTF8ByteArray(data, 0, data.length - 1);
}
public byte[] getRawRegex()
{
return Arrays.clone(data);
}
private static byte[] toNullTerminatedUTF8ByteArray(String string)
{
byte[] utf8 = Strings.toUTF8ByteArray(string);
return Arrays.append(utf8, (byte)0);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy