Skip to content

Commit

Permalink
shorten the lifespan of the route-b credential on memory
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Jun 30, 2024
1 parent f0d4abb commit e30279b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/PackageVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Update="System.Text.Json" Version="6.0.0" />
<PackageReference Update="Smdn.Devices.BP35XX" Version="[1.0.0,2.0.0)" />
<PackageReference Update="Smdn.Net.SkStackIP" Version="[1.0.0,2.0.0)" />
<PackageReference Update="Smdn.Net.SkStackIP" Version="[1.2.0,2.0.0)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,12 @@ CancellationToken cancellationToken
sessionConfiguration.PaaAddress is null
);

// TODO: reduce allocation
var rbidBufferWriter = new ArrayBufferWriter<byte>(initialCapacity: RouteBCredentials.AuthenticationIdLength);
var passwordBufferWriter = new ArrayBufferWriter<byte>(initialCapacity: RouteBCredentials.PasswordLength);

credential.WriteIdTo(rbidBufferWriter);
credential.WritePasswordTo(passwordBufferWriter);

if (shouldPerformActiveScan) {
// obtain PAN information by active scan prior to initialization
return Core(
authenticateAsPanaClientAsync: (device, ct) => device.AuthenticateAsPanaClientAsync(
rbid: rbidBufferWriter.WrittenMemory,
password: passwordBufferWriter.WrittenMemory,
writeRBID: writer => credential.WriteIdTo(writer),
writePassword: writer => credential.WritePasswordTo(writer),
scanOptions: sessionConfiguration.ActiveScanOptions,
cancellationToken: ct
)
Expand All @@ -165,8 +158,8 @@ CancellationToken cancellationToken
if (shouldResolvePaaAddress) {
return Core(
authenticateAsPanaClientAsync: (device, ct) => device.AuthenticateAsPanaClientAsync(
rbid: rbidBufferWriter.WrittenMemory,
password: passwordBufferWriter.WrittenMemory,
writeRBID: writer => credential.WriteIdTo(writer),
writePassword: writer => credential.WritePasswordTo(writer),
paaMacAddress: sessionConfiguration.PaaMacAddress!,
channel: sessionConfiguration.Channel!.Value,
panId: sessionConfiguration.PanId!.Value,
Expand All @@ -177,8 +170,8 @@ CancellationToken cancellationToken
else {
return Core(
authenticateAsPanaClientAsync: (device, ct) => device.AuthenticateAsPanaClientAsync(
rbid: rbidBufferWriter.WrittenMemory,
password: passwordBufferWriter.WrittenMemory,
writeRBID: writer => credential.WriteIdTo(writer),
writePassword: writer => credential.WritePasswordTo(writer),
paaAddress: sessionConfiguration.PaaAddress!,
channel: sessionConfiguration.Channel!.Value,
panId: sessionConfiguration.PanId!.Value,
Expand Down

0 comments on commit e30279b

Please sign in to comment.