Skip to content

Commit

Permalink
Merge pull request #81 from jerson/subkeys-metadata
Browse files Browse the repository at this point in the history
feat: Added subkeys to metadata methods
  • Loading branch information
jerson authored Jan 29, 2023
2 parents 6e36a3d + 43de1a7 commit f214e5a
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 6 deletions.
Binary file modified android/src/main/jniLibs/arm64-v8a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86_64/libopenpgp_bridge.so
Binary file not shown.
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

android.useAndroidX=true
android.enableJetifier=true
FLIPPER_VERSION=0.54.0
FLIPPER_VERSION=0.99.0
Binary file modified ios/libopenpgp_bridge.a
Binary file not shown.
82 changes: 81 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface KeyOptions {
* PubKeyAlgoEdDSA, or PubKeyAlgoECDH. If empty Curve25519 is used.
*/
curve?: Curve;

/**
* RSABits is the number of bits in new RSA keys made with NewEntity.
* If zero, then 2048 bit keys are created.
Expand Down Expand Up @@ -149,6 +149,8 @@ export interface PublicKeyMetadata {
isSubKey: boolean;
canSign: boolean;
canEncrypt: boolean;
identities?: Identity[];
subKeys?: PublicKeyMetadata[];
}
export interface PrivateKeyMetadata {
keyID: string;
Expand All @@ -159,6 +161,15 @@ export interface PrivateKeyMetadata {
isSubKey: boolean;
encrypted: boolean;
canSign: boolean;
identities?: Identity[];
subKeys?: PrivateKeyMetadata[];
}

export interface Identity {
id: string;
name: string;
comment: string;
email: string;
}

/**
Expand Down Expand Up @@ -837,6 +848,39 @@ export default class OpenPGP {
throw new Error('empty output');
}

let identities: Identity[] = [];
for (let i = 0; i < output.identitiesLength(); i++) {
const item = output.identities(i);
if (!item) {
continue;
}
identities.push({
comment: item.comment() || '',
email: item.email() || '',
name: item.name() || '',
id: item.id() || '',
});
}

let subKeys: PublicKeyMetadata[] = [];
for (let i = 0; i < output.subKeysLength(); i++) {
const item = output.subKeys(i);
if (!item) {
continue;
}
subKeys.push({
algorithm: item.algorithm() || '',
keyID: item.keyId() || '',
keyIDShort: item.keyIdShort() || '',
creationTime: item.creationTime() || '',
fingerprint: item.fingerprint() || '',
keyIDNumeric: item.keyIdNumeric() || '',
isSubKey: item.isSubKey(),
canSign: item.canSign(),
canEncrypt: item.canEncrypt(),
});
}

return {
algorithm: output.algorithm() || '',
keyID: output.keyId() || '',
Expand All @@ -847,6 +891,8 @@ export default class OpenPGP {
isSubKey: output.isSubKey(),
canSign: output.canSign(),
canEncrypt: output.canEncrypt(),
identities: identities,
subKeys: subKeys,
} as PublicKeyMetadata;
}

Expand All @@ -865,6 +911,38 @@ export default class OpenPGP {
throw new Error('empty output');
}

let identities: Identity[] = [];
for (let i = 0; i < output.identitiesLength(); i++) {
const item = output.identities(i);
if (!item) {
continue;
}
identities.push({
comment: item.comment() || '',
email: item.email() || '',
name: item.name() || '',
id: item.id() || '',
});
}

let subKeys: PrivateKeyMetadata[] = [];
for (let i = 0; i < output.subKeysLength(); i++) {
const item = output.subKeys(i);
if (!item) {
continue;
}
subKeys.push({
keyID: item.keyId() || '',
keyIDShort: item.keyIdShort() || '',
creationTime: item.creationTime() || '',
fingerprint: item.fingerprint() || '',
keyIDNumeric: item.keyIdNumeric() || '',
isSubKey: item.isSubKey(),
encrypted: item.encrypted(),
canSign: item.canSign(),
});
}

return {
keyID: output.keyId() || '',
keyIDShort: output.keyIdShort() || '',
Expand All @@ -874,6 +952,8 @@ export default class OpenPGP {
isSubKey: output.isSubKey(),
encrypted: output.encrypted(),
canSign: output.canSign(),
identities: identities,
subKeys: subKeys,
} as PrivateKeyMetadata;
}
}
31 changes: 29 additions & 2 deletions src/model/private-key-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ identitiesLength():number {
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}

subKeys(index: number, obj?:PrivateKeyMetadata):PrivateKeyMetadata|null {
const offset = this.bb!.__offset(this.bb_pos, 22);
return offset ? (obj || new PrivateKeyMetadata()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
}

subKeysLength():number {
const offset = this.bb!.__offset(this.bb_pos, 22);
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}

static startPrivateKeyMetadata(builder:flatbuffers.Builder) {
builder.startObject(9);
builder.startObject(10);
}

static addKeyId(builder:flatbuffers.Builder, keyIdOffset:flatbuffers.Offset) {
Expand Down Expand Up @@ -168,12 +178,28 @@ static startIdentitiesVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(4, numElems, 4);
}

static addSubKeys(builder:flatbuffers.Builder, subKeysOffset:flatbuffers.Offset) {
builder.addFieldOffset(9, subKeysOffset, 0);
}

static createSubKeysVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
builder.startVector(4, data.length, 4);
for (let i = data.length - 1; i >= 0; i--) {
builder.addOffset(data[i]!);
}
return builder.endVector();
}

static startSubKeysVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(4, numElems, 4);
}

static endPrivateKeyMetadata(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}

static createPrivateKeyMetadata(builder:flatbuffers.Builder, keyIdOffset:flatbuffers.Offset, keyIdShortOffset:flatbuffers.Offset, creationTimeOffset:flatbuffers.Offset, fingerprintOffset:flatbuffers.Offset, keyIdNumericOffset:flatbuffers.Offset, isSubKey:boolean, encrypted:boolean, canSign:boolean, identitiesOffset:flatbuffers.Offset):flatbuffers.Offset {
static createPrivateKeyMetadata(builder:flatbuffers.Builder, keyIdOffset:flatbuffers.Offset, keyIdShortOffset:flatbuffers.Offset, creationTimeOffset:flatbuffers.Offset, fingerprintOffset:flatbuffers.Offset, keyIdNumericOffset:flatbuffers.Offset, isSubKey:boolean, encrypted:boolean, canSign:boolean, identitiesOffset:flatbuffers.Offset, subKeysOffset:flatbuffers.Offset):flatbuffers.Offset {
PrivateKeyMetadata.startPrivateKeyMetadata(builder);
PrivateKeyMetadata.addKeyId(builder, keyIdOffset);
PrivateKeyMetadata.addKeyIdShort(builder, keyIdShortOffset);
Expand All @@ -184,6 +210,7 @@ static createPrivateKeyMetadata(builder:flatbuffers.Builder, keyIdOffset:flatbuf
PrivateKeyMetadata.addEncrypted(builder, encrypted);
PrivateKeyMetadata.addCanSign(builder, canSign);
PrivateKeyMetadata.addIdentities(builder, identitiesOffset);
PrivateKeyMetadata.addSubKeys(builder, subKeysOffset);
return PrivateKeyMetadata.endPrivateKeyMetadata(builder);
}
}
31 changes: 29 additions & 2 deletions src/model/public-key-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@ identitiesLength():number {
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}

subKeys(index: number, obj?:PublicKeyMetadata):PublicKeyMetadata|null {
const offset = this.bb!.__offset(this.bb_pos, 24);
return offset ? (obj || new PublicKeyMetadata()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
}

subKeysLength():number {
const offset = this.bb!.__offset(this.bb_pos, 24);
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}

static startPublicKeyMetadata(builder:flatbuffers.Builder) {
builder.startObject(10);
builder.startObject(11);
}

static addAlgorithm(builder:flatbuffers.Builder, algorithmOffset:flatbuffers.Offset) {
Expand Down Expand Up @@ -179,12 +189,28 @@ static startIdentitiesVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(4, numElems, 4);
}

static addSubKeys(builder:flatbuffers.Builder, subKeysOffset:flatbuffers.Offset) {
builder.addFieldOffset(10, subKeysOffset, 0);
}

static createSubKeysVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
builder.startVector(4, data.length, 4);
for (let i = data.length - 1; i >= 0; i--) {
builder.addOffset(data[i]!);
}
return builder.endVector();
}

static startSubKeysVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(4, numElems, 4);
}

static endPublicKeyMetadata(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}

static createPublicKeyMetadata(builder:flatbuffers.Builder, algorithmOffset:flatbuffers.Offset, keyIdOffset:flatbuffers.Offset, keyIdShortOffset:flatbuffers.Offset, creationTimeOffset:flatbuffers.Offset, fingerprintOffset:flatbuffers.Offset, keyIdNumericOffset:flatbuffers.Offset, isSubKey:boolean, canSign:boolean, canEncrypt:boolean, identitiesOffset:flatbuffers.Offset):flatbuffers.Offset {
static createPublicKeyMetadata(builder:flatbuffers.Builder, algorithmOffset:flatbuffers.Offset, keyIdOffset:flatbuffers.Offset, keyIdShortOffset:flatbuffers.Offset, creationTimeOffset:flatbuffers.Offset, fingerprintOffset:flatbuffers.Offset, keyIdNumericOffset:flatbuffers.Offset, isSubKey:boolean, canSign:boolean, canEncrypt:boolean, identitiesOffset:flatbuffers.Offset, subKeysOffset:flatbuffers.Offset):flatbuffers.Offset {
PublicKeyMetadata.startPublicKeyMetadata(builder);
PublicKeyMetadata.addAlgorithm(builder, algorithmOffset);
PublicKeyMetadata.addKeyId(builder, keyIdOffset);
Expand All @@ -196,6 +222,7 @@ static createPublicKeyMetadata(builder:flatbuffers.Builder, algorithmOffset:flat
PublicKeyMetadata.addCanSign(builder, canSign);
PublicKeyMetadata.addCanEncrypt(builder, canEncrypt);
PublicKeyMetadata.addIdentities(builder, identitiesOffset);
PublicKeyMetadata.addSubKeys(builder, subKeysOffset);
return PublicKeyMetadata.endPublicKeyMetadata(builder);
}
}

0 comments on commit f214e5a

Please sign in to comment.