Skip to content
Risto Seene edited this page Dec 13, 2019 · 9 revisions

Javadoc

Javadoc is located at http://open-eid.github.io/digidoc4j

Simplified API

Here are the main API interfaces and classes. This is simplified Java code example for better overview. All methods are public unless stated otherwise.

Container builder

public class ContainerBuilder {
  static ContainerBuilder aContainer();
  static ContainerBuilder aContainer(String type);
  static ContainerBuilder aContainer(DocumentType type);

  Container build();
  ContainerBuilder withConfiguration(Configuration configuration);
  ContainerBuilder withDataFile(String filePath, String mimeType) throws InvalidDataFileException;
  ContainerBuilder withDataFile(InputStream inputStream, String fileName, String mimeType) throws InvalidDataFileException;
  ContainerBuilder withDataFile(File file, String mimeType) throws InvalidDataFileException;
  ContainerBuilder withDataFile(DataFile dataFile);
  ContainerBuilder withTimeStampToken(DigestAlgorithm digestAlgorithm);
  ContainerBuilder fromExistingFile(String filePath);
  ContainerBuilder fromStream(InputStream containerInputStream);
  abstract ContainerBuilder usingTempDirectory(String temporaryDirectoryPath);
  static void setContainerImplementation(String containerType, Class containerClass);
  static void removeCustomContainerImplementations();
}

Container

Is created by ContainerBuilder.build() method.

public interface Container {
  DataFile addDataFile(String path, String mimeType);
  DataFile addDataFile(InputStream is, String fileName, String mimeType);
  DataFile addDataFile(File file, String mimeType);
  void addDataFile(DataFile dataFile);
  void addSignature(Signature signature);
  List<DataFile> getDataFiles();
  String getType();
  List<Signature> getSignatures();
  void removeDataFile(DataFile file);
  void removeSignature(Signature signature);
  void extendSignatureProfile(SignatureProfile profile);
  File saveAsFile(String filePath);
  InputStream saveAsStream();
  ValidationResult validate();
  void setTimeStampToken(DataFile timeStampToken);
  DataFile getTimeStampToken();
  Configuration getConfiguration();
  void save(OutputStream out);
}

Signature builder

public class SignatureBuilder {
  static SignatureBuilder aSignature(Container container);
  SignatureBuilder withCity(String cityName);
  SignatureBuilder withStateOrProvince(String stateOrProvince);
  SignatureBuilder withPostalCode(String postalCode);
  SignatureBuilder withCountry(String country);
  SignatureBuilder withRoles(String... roles);
  SignatureBuilder withSignatureDigestAlgorithm(DigestAlgorithm digestAlgorithm);
  SignatureBuilder withSignatureProfile(SignatureProfile signatureProfile);
  SignatureBuilder withSigningCertificate(X509Certificate certificate);
  SignatureBuilder withSignatureId(String signatureId);
  SignatureBuilder withSignatureToken(SignatureToken signatureToken);
  SignatureBuilder withEncryptionAlgorithm(EncryptionAlgorithm encryptionAlgorithm);
  SignatureBuilder withOwnSignaturePolicy(Policy signaturePolicy);
  static void setSignatureBuilderForContainerType(String containerType, Class signatureBuilderClass);
  static void removeCustomSignatureBuilders();
  abstract Signature openAdESSignature(byte[] signatureDocument);
  Signature invokeSigning() throws SignatureTokenMissingException;
  abstract DataToSign buildDataToSign() throws SignerCertificateRequiredException, ContainerWithoutFilesException;
}

Signature

Is created by SignatureBuilder.invokeSigning() method, if SignatureToken is used, or by DataToSign.finalize(byte[] signatureValue) if external signing is used.

public interface Signature {
  String getCity();
  String getCountryName();
  String getPostalCode();
  String getStateOrProvince();
  String getId();
  String getUniqueId();
  byte[] getOCSPNonce(); // For a BDOC Signature it throws a NotYetImplementedException
  X509Cert getOCSPCertificate();
  Date getOCSPResponseCreationTime();
  Date getTimeStampCreationTime();
  Date getTrustedSigningTime();
  Date getClaimedSigningTime();
  SignatureProfile getProfile();
  String getSignatureMethod();
  List<String> getSignerRoles();
  X509Cert getSigningCertificate();
  X509Cert getTimeStampTokenCertificate(); // For a DDOC Signature it throws a NotYetImplementedException
  byte[] getAdESSignature();
  ValidationResult validateSignature();
}

Data to sign

Is created by SignatureBuilder.buildDataToSign() method and used when external signing is needed (e.g. in the Web)

public class DataToSign {
  SignatureParameters getSignatureParameters();
  DigestAlgorithm getDigestAlgorithm();
  byte[] getDataToSign(); // NB! Method name changed since version 2.0.0
  Configuration getConfiguration();
  Signature finalize(byte[] signatureValue);
}

Signature token providing signing interface

Is used when SignatureBuilder.invokeSigning() is called.

public interface SignatureToken {
  X509Certificate getCertificate(); // signer certificate
  byte[] sign(DigestAlgorithm digestAlgorithm, byte[] dataToSign);
}

Signature finalizer for datafiles signing process

Used by SignatureBuilder, by SignatureBuilder generated DataToSign and for two step signing (with serialization or local storage). Can be created by SignatureFinalizerBuilder.

public interface SignatureFinalizer {
  abstract Signature finalizeSignature(byte[] signatureValue);
  abstract Signature createSignature(DSSDocument signedDocument);
  abstract byte[] getDataToBeSigned();
  Configuration getConfiguration();
  SignatureParameters getSignatureParameters();
}
You can’t perform that action at this time.