Beispiel #1
0
 private bool TryParse(byte[] buffer, out DiagnosisKeyBatch result)
 {
     result = null;
     try
     {
         var parser = new MessageParser <DiagnosisKeyBatch>(() => new DiagnosisKeyBatch());
         result = parser.ParseFrom(buffer);
         return(true);
     }
     catch (InvalidProtocolBufferException e)
     {
         _logger.LogError("Error reading IKS protobuf.", e.ToString());
         return(false);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Because of the DaysSinceOnsetOfSymptoms is a relative time span, if the system stalls over midnight for any reason, you need to rebuild with this field incremented
        /// </summary>
        /// <returns></returns>
        public byte[] Format(InteropKeyFormatterArgs[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (args.Any(x => x == null))
            {
                throw new ArgumentException("At least one element is null.", nameof(args));
            }

            var result = new DiagnosisKeyBatch();

            result.Keys.AddRange(args.Select(Map));
            return(result.ToByteArray());
        }
Beispiel #3
0
        public byte[] Serialize(DiagnosisKeyBatch batch)
        {
            var batchArray = new List <List <byte> >();

            foreach (var key in batch.Keys)
            {
                _data = new List <byte>();

                Add(key.KeyData);
                AddSeparator();
                Add(key.RollingStartIntervalNumber);
                AddSeparator();
                Add(key.RollingPeriod);
                AddSeparator();
                Add(key.TransmissionRiskLevel);
                AddSeparator();
                Add(key.VisitedCountries);
                AddSeparator();
                Add(key.Origin);
                AddSeparator();
                Add((int)key.ReportType);
                AddSeparator();
                Add(key.DaysSinceOnsetOfSymptoms);
                AddSeparator();

                batchArray.Add(_data);
            }

            // Sort by the base64 representation of the entire row serialized to EFGS format
            var s           = batchArray.OrderBy(_ => Convert.ToBase64String(_.ToArray()), StringComparer.Ordinal);
            var resultArray = new List <byte>();

            foreach (var x in s)
            {
                resultArray.AddRange(x);
            }

            return(resultArray.ToArray());
        }