Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
xAAL
Code
Python
Commits
bcda1261
Commit
bcda1261
authored
5 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Format (ruff + black config)
parent
0f9e33c2
No related branches found
No related tags found
1 merge request
!1
First try of type hints
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libs/lib/pyproject.toml
+6
-0
6 additions, 0 deletions
libs/lib/pyproject.toml
libs/lib/xaal/lib/messages.py
+24
-23
24 additions, 23 deletions
libs/lib/xaal/lib/messages.py
with
30 additions
and
23 deletions
libs/lib/pyproject.toml
+
6
−
0
View file @
bcda1261
...
@@ -29,3 +29,9 @@ dependencies = [
...
@@ -29,3 +29,9 @@ dependencies = [
Homepage
=
"https://recherche.imt-atlantique.fr/xaal/"
Homepage
=
"https://recherche.imt-atlantique.fr/xaal/"
Documentation
=
"https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/entry/code/Python/branches/0.7/libs/lib/README.rst"
Documentation
=
"https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/entry/code/Python/branches/0.7/libs/lib/README.rst"
Source
=
"https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/show/code/Python/branches/0.7/libs/lib"
Source
=
"https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/show/code/Python/branches/0.7/libs/lib"
[tool.ruff]
line-length
=
120
[tool.black]
line-length
=
120
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/messages.py
+
24
−
23
View file @
bcda1261
...
@@ -45,32 +45,33 @@ ALIVE_ADDR = UUID("00000000-0000-0000-0000-000000000000")
...
@@ -45,32 +45,33 @@ ALIVE_ADDR = UUID("00000000-0000-0000-0000-000000000000")
class
MessageType
(
Enum
):
class
MessageType
(
Enum
):
NOTIFY
=
0
NOTIFY
=
0
REQUEST
=
1
REQUEST
=
1
REPLY
=
2
REPLY
=
2
class
MessageAction
(
Enum
):
class
MessageAction
(
Enum
):
ALIVE
=
"
alive
"
ALIVE
=
"
alive
"
IS_ALIVE
=
"
is_alive
"
IS_ALIVE
=
"
is_alive
"
ATTRIBUTES_CHANGE
=
"
attributes_change
"
ATTRIBUTES_CHANGE
=
"
attributes_change
"
GET_ATTRIBUTES
=
"
get_attributes
"
GET_ATTRIBUTES
=
"
get_attributes
"
GET_DESCRIPTION
=
"
get_description
"
GET_DESCRIPTION
=
"
get_description
"
class
Message
(
object
):
class
Message
(
object
):
"""
Message object used for incomming & outgoint message
"""
"""
Message object used for incomming & outgoint message
"""
__slots__
=
[
'
version
'
,
'
timestamp
'
,
'
source
'
,
'
dev_type
'
,
'
msg_type
'
,
'
action
'
,
'
body
'
,
'
__targets
'
]
__slots__
=
[
"
version
"
,
"
timestamp
"
,
"
source
"
,
"
dev_type
"
,
"
msg_type
"
,
"
action
"
,
"
body
"
,
"
__targets
"
]
def
__init__
(
self
):
def
__init__
(
self
):
self
.
version
=
config
.
STACK_VERSION
# message API version
self
.
version
=
config
.
STACK_VERSION
# message API version
self
.
__targets
=
[]
# target property
self
.
__targets
=
[]
# target property
self
.
timestamp
=
None
# message timestamp
self
.
timestamp
=
None
# message timestamp
self
.
source
=
None
# message source
self
.
source
=
None
# message source
self
.
dev_type
=
None
# message dev_type
self
.
dev_type
=
None
# message dev_type
self
.
msg_type
=
None
# message type
self
.
msg_type
=
None
# message type
self
.
action
=
None
# message action
self
.
action
=
None
# message action
self
.
body
=
{}
# message body
self
.
body
=
{}
# message body
@property
@property
def
targets
(
self
)
->
list
:
def
targets
(
self
)
->
list
:
...
@@ -98,12 +99,12 @@ class Message(object):
...
@@ -98,12 +99,12 @@ class Message(object):
r
.
append
([
"
msg_type
"
,
MessageType
(
self
.
msg_type
)])
r
.
append
([
"
msg_type
"
,
MessageType
(
self
.
msg_type
)])
r
.
append
([
"
action
"
,
self
.
action
])
r
.
append
([
"
action
"
,
self
.
action
])
if
self
.
body
:
if
self
.
body
:
tmp
=
""
tmp
=
""
for
k
,
v
in
self
.
body
.
items
():
for
k
,
v
in
self
.
body
.
items
():
k
=
k
+
'
:
'
k
=
k
+
"
:
"
v
=
pprint
.
pformat
(
v
,
width
=
55
)
v
=
pprint
.
pformat
(
v
,
width
=
55
)
tmp
=
tmp
+
"
- %-12s %s
\n
"
%
(
k
,
v
)
tmp
=
tmp
+
"
- %-12s %s
\n
"
%
(
k
,
v
)
#tmp = tmp.strip()
#
tmp = tmp.strip()
r
.
append
([
"
body
"
,
tmp
])
r
.
append
([
"
body
"
,
tmp
])
print
(
tabulate
(
r
,
headers
=
[
"
Fied
"
,
"
Value
"
],
tablefmt
=
"
psql
"
))
print
(
tabulate
(
r
,
headers
=
[
"
Fied
"
,
"
Value
"
],
tablefmt
=
"
psql
"
))
...
@@ -187,8 +188,8 @@ class MessageFactory(object):
...
@@ -187,8 +188,8 @@ class MessageFactory(object):
buf
.
append
(
msg
.
body
)
buf
.
append
(
msg
.
body
)
clear
=
cbor
.
dumps
(
buf
)
clear
=
cbor
.
dumps
(
buf
)
# Additionnal Data == cbor serialization of the targets array
# Additionnal Data == cbor serialization of the targets array
ad
=
result
[
3
]
ad
=
result
[
3
]
nonce
=
build_nonce
(
msg
.
timestamp
)
nonce
=
build_nonce
(
msg
.
timestamp
)
payload
=
pysodium
.
crypto_aead_chacha20poly1305_ietf_encrypt
(
clear
,
ad
,
nonce
,
self
.
cipher_key
)
payload
=
pysodium
.
crypto_aead_chacha20poly1305_ietf_encrypt
(
clear
,
ad
,
nonce
,
self
.
cipher_key
)
# Final CBOR serialization
# Final CBOR serialization
...
@@ -230,7 +231,7 @@ class MessageFactory(object):
...
@@ -230,7 +231,7 @@ class MessageFactory(object):
# Replay attack, window fixed to CIPHER_WINDOW in seconds
# Replay attack, window fixed to CIPHER_WINDOW in seconds
now
=
build_timestamp
()[
0
]
# test done only on seconds ...
now
=
build_timestamp
()[
0
]
# test done only on seconds ...
if
msg_time
<
(
now
-
config
.
cipher_window
):
if
msg_time
<
(
now
-
config
.
cipher_window
):
raise
MessageParserError
(
"
Potential replay attack, message too old: %d sec
"
%
round
(
now
-
msg_time
)
)
raise
MessageParserError
(
"
Potential replay attack, message too old: %d sec
"
%
round
(
now
-
msg_time
))
if
msg_time
>
(
now
+
config
.
cipher_window
):
if
msg_time
>
(
now
+
config
.
cipher_window
):
raise
MessageParserError
(
"
Potential replay attack, message too young: %d sec
"
%
round
(
now
-
msg_time
))
raise
MessageParserError
(
"
Potential replay attack, message too young: %d sec
"
%
round
(
now
-
msg_time
))
...
...
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