Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ASN1-Model/ASN1AdaptiveTypeObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : 'ASN1AdaptiveTypeValue',
#instVars : [
'map',
'selfExpanding'
'selfExpanding',
'addedByDefault'
],
#category : 'ASN1-Model',
#package : 'ASN1-Model'
Expand All @@ -19,6 +20,12 @@ ASN1AdaptiveTypeObject class >> typedCollection [
^ ASN1TypedCollectionType type: self
]

{ #category : 'accessing' }
ASN1AdaptiveTypeObject >> addedByDefault: aKey [
addedByDefault ifNil: [ addedByDefault := OrderedCollection new ].
addedByDefault add: aKey
]

{ #category : 'accessing' }
ASN1AdaptiveTypeObject >> at: aKey [
^ self
Expand Down Expand Up @@ -282,3 +289,9 @@ ASN1AdaptiveTypeObject >> size [
ASN1AdaptiveTypeObject >> soleValue [
^ map values first
]

{ #category : 'as yet unclassified' }
ASN1AdaptiveTypeObject >> wasAddedByDefault: aKey [
addedByDefault ifNil: [ ^ false ].
^ addedByDefault includes: aKey
]
3 changes: 2 additions & 1 deletion ASN1-Tool/ASN1ReadVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ ASN1ReadVisitor >> visitCollection: aCollection [
"write the default value in the result"
element value defaultValue isAsn1
ifTrue: [ value baseValueAt: element key put: element value defaultValue ]
ifFalse: [ value at: element key put: element value defaultValue ] ].
ifFalse: [ value at: element key put: element value defaultValue ].
value addedByDefault: element key ].
elementStream next ]
ifFalse: [ isExtended ifTrue: [
(aCollection hasElementWithTag: content tag) ifFalse: [
Expand Down
39 changes: 26 additions & 13 deletions ASN1-Tool/ASN1WriteVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ Class {
#name : 'ASN1WriteVisitor',
#superclass : 'ASN1ModelVisitor',
#instVars : [
'currentValue'
'currentValue',
'skipAddedDefaults'
],
#category : 'ASN1-Tool-Visitor',
#package : 'ASN1-Tool',
#tag : 'Visitor'
}

{ #category : 'initialization' }
ASN1WriteVisitor >> initialize [
super initialize.
skipAddedDefaults := true
]

{ #category : 'exceptions' }
ASN1WriteVisitor >> mandatoryElementNotFound [
ASN1MandatoryElementNotFound signal
Expand All @@ -23,6 +30,11 @@ ASN1WriteVisitor >> push: anObject during: aBlock [
^aBlock ensure: [ currentValue := formerValue ]
]

{ #category : 'accessing' }
ASN1WriteVisitor >> skipAddedDefaults [
skipAddedDefaults := true
]

{ #category : 'visiting' }
ASN1WriteVisitor >> visit: aType [
(aType isNil ifTrue: [ Error signal: 'type cannot be nil' ]).
Expand Down Expand Up @@ -101,18 +113,19 @@ ASN1WriteVisitor >> visitSequenceType: aSequence [
object := currentValue "basicValue".
aSequence elements associations do: [ :each |
(each value class = ASN1Extension) ifFalse: [
(object includesKey: each key)
ifTrue: [
self
push: (object privAt: each key)
during: [ encoded elements add: (self visit: (aSequence elementAt: each key)) ]]
ifFalse: [
each value isOptional
ifTrue: [ each value hasDefaultValue ifTrue: [
self
push: each value defaultValue
during: [ encoded elements add: (self visit: (aSequence elementAt: each key) value) ] ] ]
ifFalse: [ self mandatoryElementNotFound ] ] ] ].
(skipAddedDefaults and: [ object wasAddedByDefault: each key ]) ifFalse: [
(object includesKey: each key)
ifTrue: [
self
push: (object privAt: each key)
during: [ encoded elements add: (self visit: (aSequence elementAt: each key)) ]]
ifFalse: [
each value isOptional
ifTrue: [ each value hasDefaultValue ifTrue: [
self
push: each value defaultValue
during: [ encoded elements add: (self visit: (aSequence elementAt: each key) defaultValue type ) ] ] ]
ifFalse: [ self mandatoryElementNotFound ] ] ] ] ].
^ encoded
]

Expand Down
Loading