(self, value, asn1Spec, encodeFun, **options)
| 43 | MAX_LENGTH = 19 |
| 44 | |
| 45 | def encodeValue(self, value, asn1Spec, encodeFun, **options): |
| 46 | # CER encoding constraints: |
| 47 | # - minutes are mandatory, seconds are optional |
| 48 | # - sub-seconds must NOT be zero / no meaningless zeros |
| 49 | # - no hanging fraction dot |
| 50 | # - time in UTC (Z) |
| 51 | # - only dot is allowed for fractions |
| 52 | |
| 53 | if asn1Spec is not None: |
| 54 | value = asn1Spec.clone(value) |
| 55 | |
| 56 | numbers = value.asNumbers() |
| 57 | |
| 58 | if self.PLUS_CHAR in numbers or self.MINUS_CHAR in numbers: |
| 59 | raise error.PyAsn1Error('Must be UTC time: %r' % value) |
| 60 | |
| 61 | if numbers[-1] != self.Z_CHAR: |
| 62 | raise error.PyAsn1Error('Missing "Z" time zone specifier: %r' % value) |
| 63 | |
| 64 | if self.COMMA_CHAR in numbers: |
| 65 | raise error.PyAsn1Error('Comma in fractions disallowed: %r' % value) |
| 66 | |
| 67 | if self.DOT_CHAR in numbers: |
| 68 | |
| 69 | isModified = False |
| 70 | |
| 71 | numbers = list(numbers) |
| 72 | |
| 73 | searchIndex = min(numbers.index(self.DOT_CHAR) + 4, len(numbers) - 1) |
| 74 | |
| 75 | while numbers[searchIndex] != self.DOT_CHAR: |
| 76 | if numbers[searchIndex] == self.ZERO_CHAR: |
| 77 | del numbers[searchIndex] |
| 78 | isModified = True |
| 79 | |
| 80 | searchIndex -= 1 |
| 81 | |
| 82 | searchIndex += 1 |
| 83 | |
| 84 | if searchIndex < len(numbers): |
| 85 | if numbers[searchIndex] == self.Z_CHAR: |
| 86 | # drop hanging comma |
| 87 | del numbers[searchIndex - 1] |
| 88 | isModified = True |
| 89 | |
| 90 | if isModified: |
| 91 | value = value.clone(numbers) |
| 92 | |
| 93 | if not self.MIN_LENGTH < len(numbers) < self.MAX_LENGTH: |
| 94 | raise error.PyAsn1Error('Length constraint violated: %r' % value) |
| 95 | |
| 96 | options.update(maxChunkSize=1000) |
| 97 | |
| 98 | return encoder.OctetStringEncoder.encodeValue( |
| 99 | self, value, asn1Spec, encodeFun, **options |
| 100 | ) |
| 101 | |
| 102 |
nothing calls this directly
no test coverage detected