Add documentation to pgp module.

This commit is contained in:
Spencer Ofwiti
2021-05-12 13:21:18 +03:00
parent 948a735baf
commit 948554563d
27 changed files with 3154 additions and 744 deletions

View File

@@ -64,6 +64,13 @@
<code>src/app/_pgp/pgp-signer.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Signable object interface </p>
</p>
<section>
@@ -115,14 +122,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="7"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:7</a></div>
<div class="io-line">Defined in <a href="" data-line="11"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:11</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The message to be signed. </p>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
@@ -138,56 +147,113 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as openpgp from &#x27;openpgp&#x27;;
// Application imports
import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
import { LoggingService } from &#x27;@app/_services/logging.service&#x27;;
const openpgp &#x3D; require(&#x27;openpgp&#x27;);
/** Signable object interface */
interface Signable {
/** The message to be signed. */
digest(): string;
}
/** Signature object interface */
interface Signature {
/** Encryption engine used. */
engine: string;
/** Encryption algorithm used */
algo: string;
/** Data to be signed. */
data: string;
/** Message digest */
digest: string;
}
/** Signer interface */
interface Signer {
/** Event triggered on successful signing of message. */
onsign(signature: Signature): void;
/** Event triggered on successful verification of a signature. */
onverify(flag: boolean): void;
/**
* Get the private key fingerprint.
* @returns A private key fingerprint.
*/
fingerprint(): string;
/**
* Load the message digest.
* @param material - A signable object.
* @returns true - If digest has been loaded successfully.
*/
prepare(material: Signable): boolean;
/**
* Verify that signature is valid.
* @param digest - The message that was signed.
* @param signature - The generated signature.
*/
verify(digest: string, signature: Signature): void;
/**
* Signs a message using a private key.
* @async
* @param digest - The message to be signed.
*/
sign(digest: string): Promise&lt;void&gt;;
}
/** Provides functionality for signing and verifying signed messages. */
class PGPSigner implements Signer {
/** Encryption engine used. */
engine &#x3D; &#x27;pgp&#x27;;
/** Encryption algorithm used */
algo &#x3D; &#x27;sha256&#x27;;
/** Message digest */
dgst: string;
/** Generated signature */
signature: Signature;
/** A keystore holding pgp keys. */
keyStore: MutableKeyStore;
/** Event triggered on successful signing of message. */
onsign: (signature: Signature) &#x3D;&gt; void;
/** Event triggered on successful verification of a signature. */
onverify: (flag: boolean) &#x3D;&gt; void;
/** A service that provides logging capabilities. */
loggingService: LoggingService;
/**
* Initializing the Signer.
* @param keyStore - A keystore holding pgp keys.
*/
constructor(keyStore: MutableKeyStore) {
this.keyStore &#x3D; keyStore;
this.onsign &#x3D; (signature: Signature) &#x3D;&gt; {};
this.onverify &#x3D; (flag: boolean) &#x3D;&gt; {};
}
/**
* Get the private key fingerprint.
* @returns A private key fingerprint.
*/
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
/**
* Load the message digest.
* @param material - A signable object.
* @returns true - If digest has been loaded successfully.
*/
public prepare(material: Signable): boolean {
this.dgst &#x3D; material.digest();
return true;
}
/**
* Verify that signature is valid.
* @param digest - The message that was signed.
* @param signature - The generated signature.
*/
public verify(digest: string, signature: Signature): void {
openpgp.signature
.readArmored(signature.data)
@@ -220,6 +286,11 @@ class PGPSigner implements Signer {
});
}
/**
* Signs a message using a private key.
* @async
* @param digest - The message to be signed.
*/
public async sign(digest: string): Promise&lt;void&gt; {
const m &#x3D; openpgp.cleartext.fromText(digest);
const pk &#x3D; this.keyStore.getPrivateKey();
@@ -251,6 +322,7 @@ class PGPSigner implements Signer {
}
}
/** @exports */
export { Signable, Signature, Signer, PGPSigner };
</code></pre>
</div>