Changeset View
Changeset View
Standalone View
Standalone View
ui/signatureguiutils.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 by Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | ***************************************************************************/ | ||||
9 | | ||||
10 | #include "signatureguiutils.h" | ||||
11 | | ||||
12 | #include <KLocalizedString> | ||||
13 | | ||||
14 | #include "core/form.h" | ||||
15 | #include "core/page.h" | ||||
16 | #include "core/document.h" | ||||
17 | | ||||
18 | namespace SignatureGuiUtils { | ||||
19 | | ||||
20 | QVector<Okular::FormFieldSignature*> getSignatureFormFields( Okular::Document *doc, bool allPages, int pageNum ) | ||||
21 | { | ||||
22 | uint curPage = allPages ? 0 : pageNum; | ||||
23 | uint endPage = allPages ? doc->pages() - 1 : pageNum; | ||||
24 | QVector<Okular::FormFieldSignature*> signatureFormFields; | ||||
25 | while ( curPage <= endPage ) | ||||
26 | { | ||||
27 | foreach ( Okular::FormField *f, doc->page( curPage )->formFields() ) | ||||
28 | { | ||||
29 | if ( f->type() == Okular::FormField::FormSignature ) | ||||
30 | { | ||||
31 | signatureFormFields.append( static_cast<Okular::FormFieldSignature*>( f ) ); | ||||
32 | } | ||||
33 | } | ||||
34 | } | ||||
35 | return signatureFormFields; | ||||
36 | } | ||||
37 | | ||||
38 | QString getReadableSignatureStatus( Okular::SignatureInfo::SignatureStatus sigStatus ) | ||||
39 | { | ||||
40 | switch ( sigStatus ) | ||||
41 | { | ||||
42 | case Okular::SignatureInfo::SignatureValid: | ||||
43 | return i18n("The signature is cryptographically valid."); | ||||
44 | case Okular::SignatureInfo::SignatureInvalid: | ||||
45 | return i18n("The signature is cryptographically invalid."); | ||||
46 | case Okular::SignatureInfo::SignatureDigestMismatch: | ||||
47 | return i18n("Digest Mismatch occurred."); | ||||
48 | case Okular::SignatureInfo::SignatureDecodingError: | ||||
49 | return i18n("The signature CMS/PKCS7 structure is malformed."); | ||||
50 | case Okular::SignatureInfo::SignatureNotFound: | ||||
51 | return i18n("The requested signature is not present in the document."); | ||||
52 | default: | ||||
53 | return i18n("The signature could not be verified."); | ||||
54 | } | ||||
55 | } | ||||
56 | | ||||
57 | QString getReadableCertStatus( Okular::SignatureInfo::CertificateStatus certStatus ) | ||||
58 | { | ||||
59 | switch ( certStatus ) | ||||
60 | { | ||||
61 | case Okular::SignatureInfo::CertificateTrusted: | ||||
62 | return i18n("Certificate is Trusted."); | ||||
63 | case Okular::SignatureInfo::CertificateUntrustedIssuer: | ||||
64 | return i18n("Certificate issuer isn't Trusted."); | ||||
65 | case Okular::SignatureInfo::CertificateUnknownIssuer: | ||||
66 | return i18n("Certificate issuer is unknown."); | ||||
67 | case Okular::SignatureInfo::CertificateRevoked: | ||||
68 | return i18n("Certificate has been Revoked."); | ||||
69 | case Okular::SignatureInfo::CertificateExpired: | ||||
70 | return i18n("Certificate has Expired."); | ||||
71 | case Okular::SignatureInfo::CertificateNotVerified: | ||||
72 | return i18n("Certificate has not yet been verified."); | ||||
73 | default: | ||||
74 | return i18n("Unknown issue with Certificate or corrupted data."); | ||||
75 | } | ||||
76 | } | ||||
77 | | ||||
78 | QString getReadableHashAlgorithm( Okular::SignatureInfo::HashAlgorithm hashAlg ) | ||||
79 | { | ||||
80 | switch ( hashAlg ) | ||||
81 | { | ||||
82 | case Okular::SignatureInfo::HashAlgorithmMd2: | ||||
83 | return i18n("MD2"); | ||||
84 | case Okular::SignatureInfo::HashAlgorithmMd5: | ||||
85 | return i18n("MD5"); | ||||
86 | case Okular::SignatureInfo::HashAlgorithmSha1: | ||||
87 | return i18n("SHA1"); | ||||
88 | case Okular::SignatureInfo::HashAlgorithmSha256: | ||||
89 | return i18n("SHA256"); | ||||
90 | case Okular::SignatureInfo::HashAlgorithmSha384: | ||||
91 | return i18n("SHA384"); | ||||
92 | case Okular::SignatureInfo::HashAlgorithmSha512: | ||||
93 | return i18n("SHA512"); | ||||
94 | case Okular::SignatureInfo::HashAlgorithmSha224: | ||||
95 | return i18n("SHA224"); | ||||
96 | default: | ||||
97 | return i18n("Unknown Algorithm"); | ||||
98 | } | ||||
99 | } | ||||
100 | | ||||
101 | QString getReadablePublicKeyType( Okular::CertificateInfo::PublicKeyType type ) | ||||
102 | { | ||||
103 | switch ( type ) | ||||
104 | { | ||||
105 | case Okular::CertificateInfo::RsaKey: | ||||
106 | return i18n("RSA"); | ||||
107 | case Okular::CertificateInfo::DsaKey: | ||||
108 | return i18n("DSA"); | ||||
109 | case Okular::CertificateInfo::EcKey: | ||||
110 | return i18n("EC"); | ||||
111 | case Okular::CertificateInfo::OtherKey: | ||||
112 | return i18n("Unknown Type"); | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | QString getReadableKeyUsage( Okular::CertificateInfo::KeyUsageExtensions kuExtensions ) | ||||
117 | { | ||||
118 | QStringList ku; | ||||
119 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuDigitalSignature ) ) | ||||
120 | ku << i18n("Digital Signature"); | ||||
121 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuNonRepudiation ) ) | ||||
122 | ku << i18n("Non-Repudiation"); | ||||
123 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuKeyEncipherment ) ) | ||||
124 | ku << i18n("Encrypt Keys"); | ||||
125 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuDataEncipherment ) ) | ||||
126 | ku << i18n("Decrypt Keys"); | ||||
127 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuKeyAgreement ) ) | ||||
128 | ku << i18n("Key Agreement"); | ||||
129 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuKeyCertSign ) ) | ||||
130 | ku << i18n("Sign Certificate"); | ||||
131 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuClrSign ) ) | ||||
132 | ku << i18n("Sign CRL"); | ||||
133 | if ( kuExtensions.testFlag( Okular::CertificateInfo::KuEncipherOnly ) ) | ||||
134 | ku << i18n("Encrypt Only"); | ||||
135 | if ( ku.isEmpty() ) | ||||
136 | ku << i18n("No Usage Specified"); | ||||
137 | return ku.join(", "); | ||||
138 | } | ||||
139 | | ||||
140 | } |