Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
deps: update protons to 5.1.0 (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Aug 11, 2022
1 parent b31ebdd commit 23a031a
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@
"err-code": "^3.0.1",
"multiformats": "^9.4.5",
"node-forge": "^1.1.0",
"protons-runtime": "^2.0.2",
"protons-runtime": "^3.1.0",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@types/mocha": "^9.0.0",
"aegir": "^37.0.12",
"benchmark": "^2.1.4",
"protons": "^4.0.1",
"protons": "^5.1.0",
"sinon": "^14.0.0",
"util": "^0.12.3",
"wherearewe": "^1.0.0"
Expand Down
142 changes: 129 additions & 13 deletions src/keys/keys.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */

import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
import type { Codec } from 'protons-runtime'
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'
import type { Codec } from 'protons-runtime'

export enum KeyType {
RSA = 'RSA',
Expand All @@ -19,7 +19,7 @@ enum __KeyTypeValues {

export namespace KeyType {
export const codec = () => {
return enumeration<typeof KeyType>(__KeyTypeValues)
return enumeration<KeyType>(__KeyTypeValues)
}
}
export interface PublicKey {
Expand All @@ -28,14 +28,72 @@ export interface PublicKey {
}

export namespace PublicKey {
let _codec: Codec<PublicKey>

export const codec = (): Codec<PublicKey> => {
return message<PublicKey>({
1: { name: 'Type', codec: KeyType.codec() },
2: { name: 'Data', codec: bytes }
})
if (_codec == null) {
_codec = message<PublicKey>((obj, writer, opts = {}) => {
if (opts.lengthDelimited !== false) {
writer.fork()
}

if (obj.Type != null) {
writer.uint32(8)
KeyType.codec().encode(obj.Type, writer)
} else {
throw new Error('Protocol error: required field "Type" was not found in object')
}

if (obj.Data != null) {
writer.uint32(18)
writer.bytes(obj.Data)
} else {
throw new Error('Protocol error: required field "Data" was not found in object')
}

if (opts.lengthDelimited !== false) {
writer.ldelim()
}
}, (reader, length) => {
const obj: any = {
Type: KeyType.RSA,
Data: new Uint8Array(0)
}

const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1:
obj.Type = KeyType.codec().decode(reader)
break
case 2:
obj.Data = reader.bytes()
break
default:
reader.skipType(tag & 7)
break
}
}

if (obj.Type == null) {
throw new Error('Protocol error: value for required field "Type" was not found in protobuf')
}

if (obj.Data == null) {
throw new Error('Protocol error: value for required field "Data" was not found in protobuf')
}

return obj
})
}

return _codec
}

export const encode = (obj: PublicKey): Uint8ArrayList => {
export const encode = (obj: PublicKey): Uint8Array => {
return encodeMessage(obj, PublicKey.codec())
}

Expand All @@ -50,14 +108,72 @@ export interface PrivateKey {
}

export namespace PrivateKey {
let _codec: Codec<PrivateKey>

export const codec = (): Codec<PrivateKey> => {
return message<PrivateKey>({
1: { name: 'Type', codec: KeyType.codec() },
2: { name: 'Data', codec: bytes }
})
if (_codec == null) {
_codec = message<PrivateKey>((obj, writer, opts = {}) => {
if (opts.lengthDelimited !== false) {
writer.fork()
}

if (obj.Type != null) {
writer.uint32(8)
KeyType.codec().encode(obj.Type, writer)
} else {
throw new Error('Protocol error: required field "Type" was not found in object')
}

if (obj.Data != null) {
writer.uint32(18)
writer.bytes(obj.Data)
} else {
throw new Error('Protocol error: required field "Data" was not found in object')
}

if (opts.lengthDelimited !== false) {
writer.ldelim()
}
}, (reader, length) => {
const obj: any = {
Type: KeyType.RSA,
Data: new Uint8Array(0)
}

const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1:
obj.Type = KeyType.codec().decode(reader)
break
case 2:
obj.Data = reader.bytes()
break
default:
reader.skipType(tag & 7)
break
}
}

if (obj.Type == null) {
throw new Error('Protocol error: value for required field "Type" was not found in protobuf')
}

if (obj.Data == null) {
throw new Error('Protocol error: value for required field "Data" was not found in protobuf')
}

return obj
})
}

return _codec
}

export const encode = (obj: PrivateKey): Uint8ArrayList => {
export const encode = (obj: PrivateKey): Uint8Array => {
return encodeMessage(obj, PrivateKey.codec())
}

Expand Down

0 comments on commit 23a031a

Please sign in to comment.