com.henricook.tls.x509.CSRUtils.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cryptoutils_2.13 Show documentation
Show all versions of cryptoutils_2.13 Show documentation
Cryptoutils for Scala 2.12 and 2.13 - Forked from Karasiq
The newest version!
package com.henricook.tls.x509
import org.bouncycastle.asn1.ASN1Encodable
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
import org.bouncycastle.asn1.x509.{Extensions, ExtensionsGenerator}
import org.bouncycastle.pkcs.PKCS10CertificationRequest
import scala.util.Try
object CSRUtils {
def extensionsOf(csr: PKCS10CertificationRequest): Seq[CertExtension] = {
Try(
CertExtension.wrap(
Extensions.getInstance(
csr
.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)
.head
.getAttrValues
.getObjectAt(0)
)
)
).getOrElse(Nil)
}
def encodeExtensions(extensions: Set[CertExtension]): ASN1Encodable = {
val extGen = new ExtensionsGenerator()
extensions.foreach { e ⇒
extGen.addExtension(e.id, e.critical, e.value)
}
extGen.generate()
}
}