本文整理汇总了Java中ee.sk.digidoc.SignedDoc类的典型用法代码示例。如果您正苦于以下问题:Java SignedDoc类的具体用法?Java SignedDoc怎么用?Java SignedDoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SignedDoc类属于ee.sk.digidoc包,在下文中一共展示了SignedDoc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeDataFileThrowsException
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
@Test(expected = DigiDoc4JException.class)
public void removeDataFileThrowsException() throws Exception {
SignedDoc ddoc = mock(SignedDoc.class);
ArrayList<ee.sk.digidoc.DataFile> mockedDataFiles = new ArrayList<>();
DataFile dataFile = mock(DataFile.class);
when(dataFile.getFileName()).thenReturn("test.txt");
mockedDataFiles.add(dataFile);
doReturn(mockedDataFiles).when(ddoc).getDataFiles();
doThrow(new DigiDocException(100, "testException", new Throwable("test Exception"))).
when(ddoc).removeDataFile(anyInt());
DDocFacade container = new DDocFacade(ddoc);
container.addDataFile("testFiles/helper-files/test.txt", "text/plain");
container.removeDataFile("test.txt");
}
示例2: getSignature
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
private ClientSignature getSignature(Signature signature,
SignedDoc signedDoc) {
Collection<String> errors = new ArrayList<>();
for (Object errorObject : signature.verify(signedDoc, false, false)) {
errors.add(errorObject.toString());
}
KeyInfo keyInfo = signature.getKeyInfo();
return new ClientSignature(
keyInfo.getSubjectFirstName() + " " + keyInfo.getSubjectLastName(),
keyInfo.getSubjectPersonalCode(),
signature.getSignedProperties().getSigningTime(),
errors);
}
示例3: parseSignedDoc
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
/**
* @throws IllegalArgumentException if content is not DDoc
* @param content
* @return
* @throws IOException
*/
public ValidatedSignedDoc parseSignedDoc(String fileName, String id, InputStream content) throws IOException {
ArrayList<DigiDocException> warnings = new ArrayList<DigiDocException>();
try {
DigiDocFactory factory = ConfigManager.instance().getDigiDocFactory();
SignedDoc doc = factory.readSignedDocFromStreamOfType(content, factory.isBdocExtension(fileName), warnings);
if (doc == null) {
throw new IllegalArgumentException("content is not a ddoc/bdoc: " + warnings);
}
return new ValidatedSignedDoc(doc, warnings);
} catch (DigiDocException e) {
throw new RuntimeException(e);
}
}
示例4: requestMobileIdSignature
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
public SignSession requestMobileIdSignature(
SignedDoc doc, String personalId, String phoneNumber) {
try {
StringBuffer challenge = new StringBuffer();
String sessionId = mobileIdService.startSigningSession(
doc,
personalId,
phoneNumber,
"ENG",
"Drive DigiDoc",
"",
"",
"",
"",
"EE",
challenge);
return new SignSession(sessionId, challenge.toString());
} catch (DigiDocException e) {
throw new RuntimeException(e);
}
}
示例5: createContainer
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
public SignedDoc createContainer(String fileName, String mimeType, InputStream content) {
try {
SignedDoc signedDoc = DigiDocGenFactory.createSignedDoc(
SignedDoc.FORMAT_DIGIDOC_XML, null, null);
DataFile dataFile = new DataFile(
signedDoc.getNewDataFileId(),
DataFile.CONTENT_EMBEDDED_BASE64,
fileName,
mimeType,
signedDoc);
byte[] contentBytes = IOUtils.toByteArray(content);
dataFile.setBase64Body(contentBytes);
dataFile.calcHashes(new ByteArrayInputStream(contentBytes));//hack to make DigiDoc save file content
signedDoc.addDataFile(dataFile);
return signedDoc;
} catch (DigiDocException | IOException e) {
throw new RuntimeException(e);
}
}
示例6: responderIDtoString
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
/**
* Get String represetation of ResponderID
* @param basResp
* @return stringified responder ID
*/
private String responderIDtoString(BasicOCSPResp basResp) {
if(basResp != null) {
ResponderID respid = basResp.getResponseData().getResponderId().toASN1Object();
Object o = ((DERTaggedObject)respid.toASN1Object()).getObject();
if(o instanceof org.bouncycastle.asn1.DEROctetString) {
org.bouncycastle.asn1.DEROctetString oc = (org.bouncycastle.asn1.DEROctetString)o;
return "byKey: " + SignedDoc.bin2hex(oc.getOctets());
} else {
X509Name name = new X509Name((ASN1Sequence)o);
return "byName: " + name.toString();
}
}
else
return null;
}
示例7: finalizeBDocSignature
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
@Test
public void finalizeBDocSignature() throws Exception {
SignedDoc doc = parseSignedDoc(getClass().getResourceAsStream("/test.bdoc"));
IdSignSession signSession = new IdSignSession("id", "digest", doc);
File file = new File();
SignatureContainerDescription signatureContainerDescription = new SignatureContainerDescription(new BlobKey("1"), "pass", "user");
when(signatureContainerDescriptionRepository.get("user")).thenReturn(new SignatureContainerDescription(new BlobKey("1"), "pass", "user"));
when(signatureContainerDescriptionRepository.getContent(signatureContainerDescription)).thenReturn(new ByteArrayInputStream("abc".getBytes()));
when(gDriveService.getFile("file", credential)).thenReturn(file);
service.finalizeSignature(signSession, "signature", "user", "file", credential);
ArgumentCaptor<byte[]> argument = ArgumentCaptor.forClass(byte[].class);
verify(gDriveService).updateContent(eq(file), argument.capture(), eq(credential));
SignedDoc parsedSignedDoc = parseSignedDoc(new ByteArrayInputStream(argument.getValue()));
assertEquals(1, parsedSignedDoc.getDataFiles().size());
assertEquals(3547, parsedSignedDoc.getDataFile(0).getSize());
}
示例8: isWarning
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
/**
* Checks is DigiDoc4JException predefined as warning for DDOC
*
* @param documentFormat format SignedDoc
* @param exception error to check
* @return is this exception warning for DDOC utility program
* @see SignedDoc
*/
public static boolean isWarning(String documentFormat, DigiDoc4JException exception) {
int errorCode = exception.getErrorCode();
return (errorCode == DigiDocException.ERR_DF_INV_HASH_GOOD_ALT_HASH
|| errorCode == DigiDocException.ERR_OLD_VER
|| errorCode == DigiDocException.ERR_TEST_SIGNATURE
|| errorCode == DigiDocException.WARN_WEAK_DIGEST
|| (errorCode == DigiDocException.ERR_ISSUER_XMLNS && !documentFormat.equals(SignedDoc.FORMAT_SK_XML)));
}
示例9: isWarning
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
private boolean isWarning(String documentFormat, DigiDoc4JException exception) {
int errorCode = exception.getErrorCode();
return (errorCode == DigiDocException.ERR_DF_INV_HASH_GOOD_ALT_HASH
|| errorCode == DigiDocException.ERR_OLD_VER
|| errorCode == DigiDocException.ERR_TEST_SIGNATURE
|| errorCode == DigiDocException.WARN_WEAK_DIGEST
|| (errorCode == DigiDocException.ERR_ISSUER_XMLNS && !documentFormat.equals(SignedDoc.FORMAT_SK_XML)));
}
示例10: open
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
public DDocContainer open(String fileName, Configuration configuration) {
logger.info("Opening DDoc container from file: " + fileName);
DDocFacade facade = new DDocFacade(configuration);
ArrayList<DigiDocException> containerOpeningExceptions = new ArrayList<>();
SignedDoc signedDoc = openSignedDoc(fileName, containerOpeningExceptions);
validateOpenedContainerExceptions(containerOpeningExceptions);
facade.setContainerOpeningExceptions(containerOpeningExceptions);
return createContainer(facade, signedDoc);
}
示例11: openSignedDoc
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
private SignedDoc openSignedDoc(String fileName, ArrayList<DigiDocException> openContainerExceptions) throws DigiDoc4JException {
try {
DigiDocFactory digFac = createDigiDocFactory();
boolean isBdoc = false;
return digFac.readSignedDocOfType(fileName, isBdoc, openContainerExceptions);
} catch (DigiDocException e) {
logger.error("Failed to open DDoc from file " + fileName + ": " + e.getMessage());
throw new DigiDoc4JException(e);
}
}
示例12: validateOpenedContainerExceptions
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
private void validateOpenedContainerExceptions(ArrayList<DigiDocException> openContainerExceptions) {
if (SignedDoc.hasFatalErrs(openContainerExceptions)) {
DigiDocException fatalError = getFatalError(openContainerExceptions);
logger.error("Container has a fatal error: " + fatalError.getMessage());
throw new DigiDoc4JException(fatalError);
}
}
示例13: createDDOCContainer
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
private void createDDOCContainer() {
logger.debug("");
try {
ddoc = new SignedDoc("DIGIDOC-XML", "1.3");
signatureParameters.setDigestAlgorithm(DigestAlgorithm.SHA1);
logger.info("DDoc container created");
} catch (DigiDocException e) {
logger.error(e.getMessage());
throw new DigiDoc4JException(e.getNestedException());
}
}
示例14: testIsWarningWhenWarningIsFound
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
@Test
public void testIsWarningWhenWarningIsFound() throws DigiDocException {
assertTrue(isWarning(SignedDoc.FORMAT_DIGIDOC_XML,
new DigiDoc4JException(DigiDocException.ERR_DF_INV_HASH_GOOD_ALT_HASH, "test")));
assertTrue(isWarning(SignedDoc.FORMAT_DIGIDOC_XML,
new DigiDoc4JException(DigiDocException.ERR_OLD_VER, "test")));
assertTrue(isWarning(SignedDoc.FORMAT_DIGIDOC_XML,
new DigiDoc4JException(DigiDocException.ERR_TEST_SIGNATURE, "test")));
assertTrue(isWarning(SignedDoc.FORMAT_DIGIDOC_XML,
new DigiDoc4JException(DigiDocException.WARN_WEAK_DIGEST, "test")));
}
示例15: testAddFileFromStreamToDDocThrowsException
import ee.sk.digidoc.SignedDoc; //导入依赖的package包/类
@Test(expected = DigiDoc4JException.class)
public void testAddFileFromStreamToDDocThrowsException() throws DigiDocException, IOException {
SignedDoc ddoc = mock(SignedDoc.class);
when(ddoc.getNewDataFileId()).thenReturn("A");
when(ddoc.getFormat()).thenReturn("SignedDoc.FORMAT_DDOC");
doThrow(new DigiDocException(100, "testException", new Throwable("test Exception"))).
when(ddoc).addDataFile(any(ee.sk.digidoc.DataFile.class));
DDocFacade container = new DDocFacade(ddoc);
try(ByteArrayInputStream is = new ByteArrayInputStream(new byte[]{0x42})) {
container.addDataFile(is, "testFromStream.txt", TEXT_MIME_TYPE);
}
}