Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pkgar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
pkgar
Commits
dd8428b4
Commit
dd8428b4
authored
4 years ago
by
SamwiseFilmore
Browse files
Options
Downloads
Patches
Plain Diff
Implement PackageBuf
parent
e689baba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Keys lib
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkgar-core/src/lib.rs
+1
-1
1 addition, 1 deletion
pkgar-core/src/lib.rs
pkgar-core/src/package.rs
+23
-5
23 additions, 5 deletions
pkgar-core/src/package.rs
with
24 additions
and
6 deletions
pkgar-core/src/lib.rs
+
1
−
1
View file @
dd8428b4
...
...
@@ -6,7 +6,7 @@ use core::mem;
pub
use
crate
::
entry
::
Entry
;
pub
use
crate
::
error
::
Error
;
pub
use
crate
::
header
::
Header
;
pub
use
crate
::
package
::
PackageSrc
;
pub
use
crate
::
package
::
{
PackageBuf
,
PackageSrc
}
;
mod
entry
;
mod
error
;
...
...
This diff is collapsed.
Click to expand it.
pkgar-core/src/package.rs
+
23
−
5
View file @
dd8428b4
use
alloc
::
vec
;
use
alloc
::
vec
::
Vec
;
use
core
::
convert
::
{
AsRef
,
TryFrom
}
;
use
core
::
convert
::
TryFrom
;
use
sodiumoxide
::
crypto
::
sign
::
PublicKey
;
...
...
@@ -58,17 +58,35 @@ pub trait PackageSrc {
}
}
impl
<
T
:
AsRef
<
[
u8
]
>>
PackageSrc
for
T
{
//TODO: Test this impl...
pub
struct
PackageBuf
<
'a
>
{
src
:
&
'a
[
u8
],
header
:
Header
,
}
impl
<
'a
>
PackageBuf
<
'a
>
{
pub
fn
new
(
src
:
&
'a
[
u8
],
public_key
:
&
PublicKey
)
->
Result
<
PackageBuf
<
'a
>
,
Error
>
{
let
zeroes
=
[
0
;
HEADER_SIZE
];
let
mut
new
=
PackageBuf
{
src
,
header
:
unsafe
{
*
Header
::
new_unchecked
(
&
zeroes
)
?
},
};
new
.header
=
*
Header
::
new
(
&
new
.src
,
&
public_key
)
?
;
Ok
(
new
)
}
}
impl
PackageSrc
for
PackageBuf
<
'_
>
{
type
Err
=
Error
;
fn
header
(
&
self
)
->
Header
{
panic!
(
"Temporary..."
);
self
.header
}
fn
read_at
(
&
mut
self
,
offset
:
u64
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
,
Error
>
{
let
start
=
usize
::
try_from
(
offset
)
.map_err
(
Error
::
TryFromInt
)
?
;
let
len
=
self
.
as_ref
()
.len
();
let
len
=
self
.
src
.len
();
if
start
>=
len
{
return
Ok
(
0
);
}
...
...
@@ -77,7 +95,7 @@ impl<T: AsRef<[u8]>> PackageSrc for T {
if
end
>
len
{
end
=
len
;
}
buf
.copy_from_slice
(
&
self
.
as_ref
()
[
start
..
end
]);
buf
.copy_from_slice
(
&
self
.
src
[
start
..
end
]);
Ok
(
end
.checked_sub
(
start
)
.unwrap
())
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment