Skip to content

Commit e9d0dd1

Browse files
authored
Merge pull request #74 from jerson/ecc
ECC initial support
2 parents 6299a02 + 4f76b80 commit e9d0dd1

File tree

16 files changed

+296
-56
lines changed

16 files changed

+296
-56
lines changed

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,63 @@ const encrypted = await OpenPGP.encrypt("sample text" publicKeys);
108108
```typescript
109109
import OpenPGP from "react-native-fast-openpgp";
110110

111+
export enum Algorithm {
112+
RSA = 0,
113+
ECDSA = 1,
114+
EDDSA = 2,
115+
ECHD = 3,
116+
DSA = 4,
117+
ELGAMAL = 5,
118+
}
119+
120+
export enum Curve {
121+
CURVE25519 = 0,
122+
CURVE448 = 1,
123+
P256 = 2,
124+
P384 = 3,
125+
P521 = 4,
126+
SECP256K1 = 5,
127+
BRAINPOOLP256 = 6,
128+
BRAINPOOLP384 = 7,
129+
BRAINPOOLP512 = 8,
130+
}
111131

112132
export enum Hash {
113-
SHA256 = 0,
114-
SHA224 = 1,
115-
SHA384 = 2,
116-
SHA512 = 3,
133+
SHA256 = 0,
134+
SHA224 = 1,
135+
SHA384 = 2,
136+
SHA512 = 3,
117137
}
118138

119139
export enum Compression {
120-
NONE = 0,
121-
ZLIB = 1,
122-
ZIP = 2,
140+
NONE = 0,
141+
ZLIB = 1,
142+
ZIP = 2,
123143
}
124144

125145
export enum Cipher {
126-
AES128 = 0,
127-
AES192 = 1,
128-
AES256 = 2,
146+
AES128 = 0,
147+
AES192 = 1,
148+
AES256 = 2,
149+
DES = 3,
150+
CAST5 = 4,
129151
}
130152

131153
export interface KeyOptions {
154+
/**
155+
* The public key algorithm to use - will always create a signing primary
156+
* key and encryption subkey.
157+
* @default RSA
158+
*/
159+
algorithm?: Algorithm;
160+
161+
/**
162+
* Curve configures the desired packet.Curve if the Algorithm is PubKeyAlgoECDSA,
163+
* PubKeyAlgoEdDSA, or PubKeyAlgoECDH. If empty Curve25519 is used.
164+
* @default CURVE25519
165+
*/
166+
curve?: Curve;
167+
132168
/**
133169
* RSABits is the number of bits in new RSA keys made with NewEntity.
134170
* If zero, then 2048 bit keys are created.
@@ -139,7 +175,7 @@ export interface KeyOptions {
139175
/**
140176
* Cipher is the cipher to be used.
141177
* If zero, AES-128 is used.
142-
* @default aes128
178+
* @default AES128
143179
*/
144180
cipher?: Cipher;
145181

@@ -154,7 +190,7 @@ export interface KeyOptions {
154190
/**
155191
* Hash is the default hash function to be used.
156192
* If zero, SHA-256 is used.
157-
* @default sha256
193+
* @default SHA256
158194
*/
159195
hash?: Hash;
160196

22.6 KB
Binary file not shown.
17.3 KB
Binary file not shown.
21.3 KB
Binary file not shown.
22.6 KB
Binary file not shown.

example/src/modules/Generate.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Button} from "react-native";
22
import React, {useState} from "react";
3-
import OpenPGP from 'react-native-fast-openpgp';
3+
import OpenPGP, { Algorithm, Curve } from 'react-native-fast-openpgp';
44
import SectionContainer from "../components/SectionContainer";
55
import SectionTitle from "../components/SectionTitle";
66
import SectionResult from "../components/SectionResult";
@@ -29,7 +29,8 @@ export default function ({}: Props) {
2929
3030
passphrase: 'test',
3131
keyOptions: {
32-
rsaBits: 2048,
32+
algorithm:Algorithm.ECDSA,
33+
curve:Curve.P256
3334
},
3435
});
3536
setKeyPair(output);

ios/libopenpgp_bridge.a

67.9 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-fast-openpgp",
3-
"version": "2.4.5",
3+
"version": "2.5.0",
44
"description": "library for use openPGP",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/bridge.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
export { Algorithm } from './model/algorithm';
12
export { Cipher } from './model/cipher';
23
export { Compression } from './model/compression';
4+
export { Curve } from './model/curve';
35
export { Entity } from './model/entity';
46
export { FileHints } from './model/file-hints';
57
export { Hash } from './model/hash';

src/index.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ import './shim';
2828
const FastOpenPGPNativeModules = (NativeModules as NativeModulesDef)
2929
.FastOpenPGP;
3030

31+
export enum Algorithm {
32+
RSA = 0,
33+
ECDSA = 1,
34+
EDDSA = 2,
35+
ECHD = 3,
36+
DSA = 4,
37+
ELGAMAL = 5,
38+
}
39+
40+
export enum Curve {
41+
CURVE25519 = 0,
42+
CURVE448 = 1,
43+
P256 = 2,
44+
P384 = 3,
45+
P521 = 4,
46+
SECP256K1 = 5,
47+
BRAINPOOLP256 = 6,
48+
BRAINPOOLP384 = 7,
49+
BRAINPOOLP512 = 8,
50+
}
51+
3152
export enum Hash {
3253
SHA256 = 0,
3354
SHA224 = 1,
@@ -45,9 +66,23 @@ export enum Cipher {
4566
AES128 = 0,
4667
AES192 = 1,
4768
AES256 = 2,
69+
DES = 3,
70+
CAST5 = 4,
4871
}
4972

5073
export interface KeyOptions {
74+
/**
75+
* The public key algorithm to use - will always create a signing primary
76+
* key and encryption subkey.
77+
*/
78+
algorithm?: Algorithm;
79+
80+
/**
81+
* Curve configures the desired packet.Curve if the Algorithm is PubKeyAlgoECDSA,
82+
* PubKeyAlgoEdDSA, or PubKeyAlgoECDH. If empty Curve25519 is used.
83+
*/
84+
curve?: Curve;
85+
5186
/**
5287
* RSABits is the number of bits in new RSA keys made with NewEntity.
5388
* If zero, then 2048 bit keys are created.
@@ -105,12 +140,15 @@ export interface KeyPair {
105140
}
106141

107142
export interface PublicKeyMetadata {
143+
algorithm: string;
108144
keyID: string;
109145
keyIDShort: string;
110146
creationTime: string;
111147
fingerprint: string;
112148
keyIDNumeric: string;
113149
isSubKey: boolean;
150+
canSign: boolean;
151+
canEncrypt: boolean;
114152
}
115153
export interface PrivateKeyMetadata {
116154
keyID: string;
@@ -120,6 +158,7 @@ export interface PrivateKeyMetadata {
120158
keyIDNumeric: string;
121159
isSubKey: boolean;
122160
encrypted: boolean;
161+
canSign: boolean;
123162
}
124163

125164
/**
@@ -730,6 +769,10 @@ export default class OpenPGP {
730769
model.KeyOptions.addCompressionLevel(builder, options.compressionLevel);
731770
typeof options.hash !== 'undefined' &&
732771
model.KeyOptions.addHash(builder, options.hash);
772+
typeof options.algorithm !== 'undefined' &&
773+
model.KeyOptions.addAlgorithm(builder, options.algorithm);
774+
typeof options.curve !== 'undefined' &&
775+
model.KeyOptions.addCurve(builder, options.curve);
733776
typeof options.rsaBits !== 'undefined' &&
734777
model.KeyOptions.addRsaBits(builder, options.rsaBits);
735778

@@ -795,12 +838,15 @@ export default class OpenPGP {
795838
}
796839

797840
return {
841+
algorithm: output.algorithm() || '',
798842
keyID: output.keyId() || '',
799843
keyIDShort: output.keyIdShort() || '',
800844
creationTime: output.creationTime() || '',
801845
fingerprint: output.fingerprint() || '',
802846
keyIDNumeric: output.keyIdNumeric() || '',
803847
isSubKey: output.isSubKey(),
848+
canSign: output.canSign(),
849+
canEncrypt: output.canEncrypt(),
804850
} as PublicKeyMetadata;
805851
}
806852

@@ -827,6 +873,7 @@ export default class OpenPGP {
827873
keyIDNumeric: output.keyIdNumeric() || '',
828874
isSubKey: output.isSubKey(),
829875
encrypted: output.encrypted(),
876+
canSign: output.canSign(),
830877
} as PrivateKeyMetadata;
831878
}
832879
}

0 commit comments

Comments
 (0)