Skip to content

Commit

Permalink
unthrow
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed May 6, 2023
1 parent f3b5421 commit 4eee705
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 260 deletions.
130 changes: 65 additions & 65 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
},
"dependencies": {
"@hazae41/arrays": "^1.1.1",
"@hazae41/binary": "^1.2.21",
"@hazae41/binary": "^1.2.22",
"@hazae41/bitset": "^1.0.1",
"@hazae41/bytes": "^1.1.5",
"@hazae41/cursor": "^1.1.7",
"@hazae41/option": "^1.0.5",
"@hazae41/result": "^1.0.14"
"@hazae41/bytes": "^1.1.6",
"@hazae41/cursor": "^1.1.8",
"@hazae41/option": "^1.0.6",
"@hazae41/result": "^1.0.16"
},
"devDependencies": {
"@hazae41/phobos": "^1.0.10",
"@rollup/plugin-typescript": "^11.1.0",
"@types/node": "^18.16.3",
"@types/node": "^20.1.0",
"rimraf": "^5.0.0",
"rollup": "^3.21.3",
"rollup": "^3.21.5",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-node-externals": "^5.1.2",
"typescript": "^5.0.4"
Expand Down
16 changes: 8 additions & 8 deletions src/mods/length/length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export namespace Length {
export namespace DER {

export function tryRead(cursor: Cursor): Result<Length, Error> {
return Result.unthrowSync(() => {
const first = cursor.tryReadUint8().throw()
return Result.unthrowSync(t => {
const first = cursor.tryReadUint8().throw(t)

if (first < 128)
return new Ok(new Length(first))
Expand All @@ -55,10 +55,10 @@ export namespace Length {
let value = 0

for (let i = 0; i < count; i++)
value = (value * 256) + cursor.tryReadUint8().throw()
value = (value * 256) + cursor.tryReadUint8().throw(t)

return new Ok(new Length(value))
}, Error)
})
}

}
Expand Down Expand Up @@ -91,18 +91,18 @@ export namespace Length {
}

tryWrite(cursor: Cursor): Result<void, Error> {
return Result.unthrowSync(() => {
return Result.unthrowSync(t => {
const count = new Bitset(this.values.length, 8)
.enableBE(0)
.value

cursor.tryWriteUint8(count).throw()
cursor.tryWriteUint8(count).throw(t)

for (const value of this.values)
cursor.tryWriteUint8(value).throw()
cursor.tryWriteUint8(value).throw(t)

return Ok.void()
}, Error)
})
}

}
Expand Down
26 changes: 13 additions & 13 deletions src/mods/triplets/bit_string/bit_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ export namespace BitString {
}

tryWrite(cursor: Cursor): Result<void, Error> {
return Result.unthrowSync(() => {
this.type.tryWrite(cursor).throw()
this.length.tryWrite(cursor).throw()
return Result.unthrowSync(t => {
this.type.tryWrite(cursor).throw(t)
this.length.tryWrite(cursor).throw(t)

cursor.tryWriteUint8(this.padding).throw()
cursor.tryWrite(this.bytes).throw()
cursor.tryWriteUint8(this.padding).throw(t)
cursor.tryWrite(this.bytes).throw(t)

return Ok.void()
}, Error)
})
}

static tryRead(cursor: Cursor): Result<BitString, Error> {
return Result.unthrowSync(() => {
const type = Type.DER.tryRead(cursor).throw()
const length = Length.DER.tryRead(cursor).throw()
return Result.unthrowSync(t => {
const type = Type.DER.tryRead(cursor).throw(t)
const length = Length.DER.tryRead(cursor).throw(t)

const content = cursor.tryRead(length.value).throw()
const content = cursor.tryRead(length.value).throw(t)
const subcursor = new Cursor(content)

const padding = subcursor.tryReadUint8().throw()
const bytes = subcursor.tryRead(subcursor.remaining).throw()
const padding = subcursor.tryReadUint8().throw(t)
const bytes = subcursor.tryRead(subcursor.remaining).throw(t)

return new Ok(new BitString(type, padding, bytes))
}, Error)
})
}

}
Expand Down
20 changes: 10 additions & 10 deletions src/mods/triplets/boolean/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@ export namespace Boolean {
}

tryWrite(cursor: Cursor): Result<void, Error> {
return Result.unthrowSync(() => {
this.type.tryWrite(cursor).throw()
this.length.tryWrite(cursor).throw()
return Result.unthrowSync(t => {
this.type.tryWrite(cursor).throw(t)
this.length.tryWrite(cursor).throw(t)

cursor.tryWriteUint8(this.value).throw()
cursor.tryWriteUint8(this.value).throw(t)

return Ok.void()
}, Error)
})
}

static tryRead(cursor: Cursor): Result<Boolean, Error | InvalidLengthError> {
return Result.unthrowSync(() => {
const type = Type.DER.tryRead(cursor).throw()
const length = Length.DER.tryRead(cursor).throw()
return Result.unthrowSync(t => {
const type = Type.DER.tryRead(cursor).throw(t)
const length = Length.DER.tryRead(cursor).throw(t)

if (length.value !== 1)
return new Err(new InvalidLengthError(`Boolean`, length.value))

const value = cursor.tryReadUint8().throw()
const value = cursor.tryReadUint8().throw(t)

return new Ok(new Boolean(type, value))
}, Error)
})
}
}
}
Loading

0 comments on commit 4eee705

Please sign in to comment.