Skip to content

Commit

Permalink
Merge pull request #19 from iffy/i18-gcsafe
Browse files Browse the repository at this point in the history
Annotate dbus.append calls with {.gcsafe.}
  • Loading branch information
iffy committed Feb 23, 2024
2 parents 72c566f + 0787362 commit 9df7b88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nimversion: [stable]
version: ['binary:stable']
steps:
- uses: actions/checkout@v1
- uses: iffy/install-nim@master
- uses: iffy/install-nim@v5
with:
nimversion: ${{ matrix.nimversion }}
version: ${{ matrix.version }}
- name: Install deps
run: |
nimble refresh
Expand All @@ -34,13 +34,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
nimversion: [stable]
version: ['binary:stable']
os: [macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- uses: iffy/install-nim@master
- uses: iffy/install-nim@v5
with:
nimversion: ${{ matrix.nimversion }}
version: ${{ matrix.version }}
- name: Install deps
run: |
nimble refresh
Expand Down
1 change: 1 addition & 0 deletions changes/fix-Annotate-dbusappend-calls-20240222-212813.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Annotate dbus.append calls with {.gcsafe.}
41 changes: 25 additions & 16 deletions src/keyring/linux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ proc openSession(bus:Bus): ObjectPath =
SERVICE_INTERFACE,
"OpenSession",
)
msg.append("plain")
msg.append(newVariant[string](""))
{.gcsafe.}:
msg.append("plain")
{.gcsafe.}:
msg.append(newVariant[string](""))
let open_result = bus.call(msg)
result = open_result[^1].objectPathValueOrFail("in openSession")
doAssert $result != ""
Expand All @@ -83,7 +85,8 @@ proc unlock(bus:Bus, thing:ObjectPath) =
SERVICE_INTERFACE,
"Unlock",
)
unlock_msg.append(@[thing])
{.gcsafe.}:
unlock_msg.append(@[thing])
let unlock_result = bus.call(unlock_msg)
doAssert $(unlock_result[0].arrayValue[0].objectPathValueOrFail("in unlock")) == $thing
doAssert $(unlock_result[1].objectPathValueOrFail("in unlock")) == "/" # special value indicating no prompt needed
Expand Down Expand Up @@ -146,18 +149,21 @@ proc setPassword*(service: string, username: string, password: string) {.gcsafe,
(SS_PREFIX & "Item.Attributes").asDbusValue(),
newVariant(inner).asDbusValue()
)
create_msg.append(outer)
{.gcsafe.}:
create_msg.append(outer)
# TODO: this is where in-transit encryption would happen
create_msg.append(
DbusValue(kind: dtStruct, structValues: @[
session_object_path.asDbusValue(),
"".toByteArray().asDbusValue(),
password.toByteArray().asDbusValue(),
"text/plain".asDbusValue(),
])
)
{.gcsafe.}:
create_msg.append(
DbusValue(kind: dtStruct, structValues: @[
session_object_path.asDbusValue(),
"".toByteArray().asDbusValue(),
password.toByteArray().asDbusValue(),
"text/plain".asDbusValue(),
])
)
# create_msg.append(password)
create_msg.append(true)
{.gcsafe.}:
create_msg.append(true)
discard bus.call(create_msg)

proc getPassword*(service: string, username: string): Option[string] {.gcsafe, raises: [KeyringError, DbusException, ValueError, Exception].} =
Expand All @@ -177,7 +183,8 @@ proc getPassword*(service: string, username: string): Option[string] {.gcsafe, r
"service": service,
"username": username,
}.toTable()
search_msg.append(attrs)
{.gcsafe.}:
search_msg.append(attrs)
var found_item_path:ObjectPath
try:
let search_result = bus.call(search_msg)
Expand All @@ -195,7 +202,8 @@ proc getPassword*(service: string, username: string): Option[string] {.gcsafe, r
ITEM_INTERFACE,
"GetSecret",
)
get_msg.append(session_object_path)
{.gcsafe.}:
get_msg.append(session_object_path)
try:
let get_result = bus.call(get_msg)
let secret = get_result[0]
Expand All @@ -221,7 +229,8 @@ proc deletePassword*(service: string, username: string) {.gcsafe, raises: [Keyri
"service": service,
"username": username,
}.toTable()
search_msg.append(attrs)
{.gcsafe.}:
search_msg.append(attrs)
var found_item_path:ObjectPath
let search_result = bus.call(search_msg)
doAssert search_result[0].kind == dtArray
Expand Down

0 comments on commit 9df7b88

Please sign in to comment.