-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeServerModule.py
executable file
·46 lines (35 loc) · 1.53 KB
/
TimeServerModule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# 2nd-party imports.
import CommonModule
def Tokens(num_of_ecus=1):
Token = CommonModule.INTEGER_SIZE_IN_BYTES
CommonModule.log('Token', Token)
CommonModule.log('# of ECUs', num_of_ecus, unit=' ECUs')
tokens = num_of_ecus * Token
CommonModule.log('Tokens', tokens)
return tokens
def SequenceOfTokens(num_of_ecus=1):
'''https://github.com/uptane/asn1/blob/master/TimeServerModule.asn1'''
numberOfTokens = CommonModule.LENGTH_SIZE_IN_BYTES
tokens = Tokens(num_of_ecus=num_of_ecus)
sequenceOfTokens = numberOfTokens + tokens
CommonModule.log('SequenceOfTokens', sequenceOfTokens)
return sequenceOfTokens
def CurrentTime(num_of_ecus=1, num_of_keys_for_time_server=1):
'''https://github.com/uptane/asn1/blob/master/TimeServerModule.asn1'''
numberOfSignatures = CommonModule.LENGTH_SIZE_IN_BYTES
signatures = CommonModule.Signatures(num_of_keys_for_time_server)
numberOfTokens = CommonModule.LENGTH_SIZE_IN_BYTES
tokens = Tokens(num_of_ecus=num_of_ecus)
timestamp = CommonModule.UTCDATETIME_SIZE_IN_BYTES
signed = numberOfTokens + tokens + timestamp
currentTime = signed + numberOfSignatures + signatures
CommonModule.log('CurrentTime', currentTime)
return currentTime
if __name__ == '__main__':
num_of_ecus = 100
sequenceOfTokens = SequenceOfTokens(num_of_ecus=num_of_ecus)
currentTime = CurrentTime(num_of_ecus=num_of_ecus)
total = sequenceOfTokens + currentTime
CommonModule.log('SequenceOfTokens + CurrentTime', total)
CommonModule.time(CommonModule.iso_tp_overhead(total))