From f6f8dc8cbc54545b0b72e691b22a0b5e2ae83993 Mon Sep 17 00:00:00 2001 From: Norbert Hartl Date: Tue, 23 Sep 2025 16:18:34 +0200 Subject: [PATCH] - introduced tracking of vales that are added over defaults - added special mode in write visitor to skip the values that have been added through defaults --- ASN1-Model/ASN1AdaptiveTypeObject.class.st | 15 +++- ASN1-Tool/ASN1.extension.st | 52 ++++++------- ASN1-Tool/ASN1ChoiceType.extension.st | 6 +- ASN1-Tool/ASN1DefinitionObject.extension.st | 12 +-- ASN1-Tool/ASN1ElementNotFound.class.st | 10 ++- ASN1-Tool/ASN1EncodedType.extension.st | 6 +- ASN1-Tool/ASN1ExplicitTags.extension.st | 6 +- ASN1-Tool/ASN1ImplicitTags.extension.st | 6 +- .../ASN1MandatoryElementNotFound.class.st | 10 ++- ASN1-Tool/ASN1ModelRoot.extension.st | 12 +-- ASN1-Tool/ASN1Module.extension.st | 16 ++-- ASN1-Tool/ASN1ObjectFactory.class.st | 20 ++--- ASN1-Tool/ASN1PrimitiveType.extension.st | 6 +- ASN1-Tool/ASN1ReadVisitor.class.st | 61 ++++++++------- ASN1-Tool/ASN1StructureError.class.st | 8 +- ASN1-Tool/ASN1TagEnvironment.extension.st | 4 +- ASN1-Tool/ASN1TaggedType.extension.st | 6 +- ASN1-Tool/ASN1UnexpectedType.class.st | 8 +- ASN1-Tool/ASN1WriteVisitor.class.st | 75 +++++++++++-------- ASN1-Tool/Object.extension.st | 4 +- ASN1-Tool/package.st | 2 +- 21 files changed, 193 insertions(+), 152 deletions(-) diff --git a/ASN1-Model/ASN1AdaptiveTypeObject.class.st b/ASN1-Model/ASN1AdaptiveTypeObject.class.st index ef0f8da..3914c99 100644 --- a/ASN1-Model/ASN1AdaptiveTypeObject.class.st +++ b/ASN1-Model/ASN1AdaptiveTypeObject.class.st @@ -3,7 +3,8 @@ Class { #superclass : 'ASN1AdaptiveTypeValue', #instVars : [ 'map', - 'selfExpanding' + 'selfExpanding', + 'addedByDefault' ], #category : 'ASN1-Model', #package : 'ASN1-Model' @@ -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 @@ -282,3 +289,9 @@ ASN1AdaptiveTypeObject >> size [ ASN1AdaptiveTypeObject >> soleValue [ ^ map values first ] + +{ #category : 'as yet unclassified' } +ASN1AdaptiveTypeObject >> wasAddedByDefault: aKey [ + addedByDefault ifNil: [ ^ false ]. + ^ addedByDefault includes: aKey +] diff --git a/ASN1-Tool/ASN1.extension.st b/ASN1-Tool/ASN1.extension.st index 99aa3dc..efcd142 100644 --- a/ASN1-Tool/ASN1.extension.st +++ b/ASN1-Tool/ASN1.extension.st @@ -1,17 +1,17 @@ -Extension { #name : #ASN1 } +Extension { #name : 'ASN1' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> defaultModule [ self subclassResponsibility ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> encodeToByteArray: anObject usingModule: aModule [ ^ aModule encodeToByteArray: anObject ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> encodeToByteArray: aValue usingType: aType [ ^ ByteArray streamContents: [:stream| self @@ -20,24 +20,24 @@ ASN1 class >> encodeToByteArray: aValue usingType: aType [ usingType: aType] ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> octetStringFrom: anEncodedValue withTagNumber: aNumber [ ^ (anEncodedValue valueWithTag: ( ASN1Tag clazz: 'APPLICATION' number: aNumber)) ifNotNil: [ :value | ASN1OctetStringType decode: value contents ] ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingModule: aModule [ ^ aModule read: anEncodedValue ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingModule: aModule inContext: aContext [ ^ aModule read: anEncodedValue inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType [ ^ self read: anEncodedValue @@ -45,7 +45,7 @@ ASN1 class >> read: anEncodedValue usingType: aType [ inContext: nil ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType as: aClass [ ^ self read: anEncodedValue @@ -54,7 +54,7 @@ ASN1 class >> read: anEncodedValue usingType: aType as: aClass [ as: aClass ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext [ ^ self read: anEncodedValue @@ -63,7 +63,7 @@ ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext [ as: nil ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext as: aClass [ ^self read: anEncodedValue @@ -73,7 +73,7 @@ ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext as: aCla as: aClass ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErrors: aBoolean [ ^ self read: anEncodedValue @@ -83,7 +83,7 @@ ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErro as: nil ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErrors: aBoolean as: aClass [ ^ self read: anEncodedValue @@ -95,7 +95,7 @@ ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErro ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErrors: aBoolean as: aClass reader: aVisitor [ ^ [ aVisitor skipErrors: (aBoolean ifNil: [ false ]); @@ -106,14 +106,14 @@ ASN1 class >> read: anEncodedValue usingType: aType inContext: aContext skipErro ifNotNil: [ aContext moduleDefiningOid: err oid ] ) ] ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream [ ^ self readFrom: aStream readStream usingModule: self defaultModule ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream inContext: aContext [ ^ self readFrom: aStream readStream @@ -121,17 +121,17 @@ ASN1 class >> readFrom: aStream inContext: aContext [ inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream usingModule: aModule [ ^ aModule readFrom: aStream ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream usingModule: aModule inContext: aContext [ ^ aModule readFrom: aStream inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream usingType: aType [ ^ self readFrom: aStream @@ -140,7 +140,7 @@ ASN1 class >> readFrom: aStream usingType: aType [ ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readFrom: aStream usingType: aType inContext: aContext [ ^ self read: (self readEncodedValuesFrom: aStream) @@ -148,35 +148,35 @@ ASN1 class >> readFrom: aStream usingType: aType inContext: aContext [ inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> readVisitorClass [ ^ ASN1ReadVisitor ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> write: anObject on: aStream usingType: aType [ self writeEncodedValues: ( self write: anObject usingType: aType ) on: aStream ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> write: anObject usingModule: aModule [ ^ aModule write: anObject ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> write: anObject usingType: aType [ ^ self writeVisitorClass new write: anObject using: aType. ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> writeEncodedValues: aTaggedValue on: aStream [ (self codecStreamClass on: aStream) nextPut: aTaggedValue ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1 class >> writeVisitorClass [ ^ ASN1WriteVisitor ] diff --git a/ASN1-Tool/ASN1ChoiceType.extension.st b/ASN1-Tool/ASN1ChoiceType.extension.st index 3274b67..934203e 100644 --- a/ASN1-Tool/ASN1ChoiceType.extension.st +++ b/ASN1-Tool/ASN1ChoiceType.extension.st @@ -1,12 +1,12 @@ -Extension { #name : #ASN1ChoiceType } +Extension { #name : 'ASN1ChoiceType' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ChoiceType >> decodeTaggedValue: aTaggedValue tagEnvironment: aTagEnvironment [ "choices are always explicit" ^ ASN1ExplicitTags readEncodedValue: aTaggedValue ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ChoiceType >> encodeTaggedValue: aTaggedValue tagEnvironment: aTagEnvironment outerTag: aTag [ "choices are always explicit" diff --git a/ASN1-Tool/ASN1DefinitionObject.extension.st b/ASN1-Tool/ASN1DefinitionObject.extension.st index 1ef8f21..4f1b54b 100644 --- a/ASN1-Tool/ASN1DefinitionObject.extension.st +++ b/ASN1-Tool/ASN1DefinitionObject.extension.st @@ -1,20 +1,20 @@ -Extension { #name : #ASN1DefinitionObject } +Extension { #name : 'ASN1DefinitionObject' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1DefinitionObject >> encodeToByteArray: anEncodedObject [ ^ ASN1 encodeToByteArray: anEncodedObject usingType: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1DefinitionObject >> read: anEncodedValue [ ^ ASN1 read: anEncodedValue usingType: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1DefinitionObject >> read: anEncodedValue as: aClass [ ^ ASN1 read: anEncodedValue @@ -23,14 +23,14 @@ ASN1DefinitionObject >> read: anEncodedValue as: aClass [ as: aClass ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1DefinitionObject >> readFrom: aStream [ ^ ASN1 readFrom: aStream usingType: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1DefinitionObject >> write: anEncodedObject [ ^ ASN1 write: anEncodedObject diff --git a/ASN1-Tool/ASN1ElementNotFound.class.st b/ASN1-Tool/ASN1ElementNotFound.class.st index 1ffbecd..8ada240 100644 --- a/ASN1-Tool/ASN1ElementNotFound.class.st +++ b/ASN1-Tool/ASN1ElementNotFound.class.st @@ -1,10 +1,12 @@ Class { - #name : #ASN1ElementNotFound, - #superclass : #ASN1StructureError, - #category : 'ASN1-Tool-Exception' + #name : 'ASN1ElementNotFound', + #superclass : 'ASN1StructureError', + #category : 'ASN1-Tool-Exception', + #package : 'ASN1-Tool', + #tag : 'Exception' } -{ #category : #testing } +{ #category : 'testing' } ASN1ElementNotFound >> isResumable [ ^ true ] diff --git a/ASN1-Tool/ASN1EncodedType.extension.st b/ASN1-Tool/ASN1EncodedType.extension.st index 32037eb..2b794d4 100644 --- a/ASN1-Tool/ASN1EncodedType.extension.st +++ b/ASN1-Tool/ASN1EncodedType.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #ASN1EncodedType } +Extension { #name : 'ASN1EncodedType' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1EncodedType >> decodeTaggedValue: aTaggedValue tagEnvironment: aTagEnvironment [ ^ aTagEnvironment readEncodedValue: aTaggedValue ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1EncodedType >> encodeTaggedValue: aTaggedValue tagEnvironment: aTagEnvironment outerTag: aTag [ ^ aTagEnvironment writeEncodedValue: aTaggedValue withTag: aTag ] diff --git a/ASN1-Tool/ASN1ExplicitTags.extension.st b/ASN1-Tool/ASN1ExplicitTags.extension.st index fc3ee8f..a04924d 100644 --- a/ASN1-Tool/ASN1ExplicitTags.extension.st +++ b/ASN1-Tool/ASN1ExplicitTags.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #ASN1ExplicitTags } +Extension { #name : 'ASN1ExplicitTags' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ExplicitTags class >> readEncodedValue: anEncodedValue [ ^ anEncodedValue firstElement ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ExplicitTags class >> writeEncodedValue: anEncodedValue withTag: aTag [ "in explicit mode we add another tag around the current tagged value" ^ ASN1EncodedConstructedValue new diff --git a/ASN1-Tool/ASN1ImplicitTags.extension.st b/ASN1-Tool/ASN1ImplicitTags.extension.st index 01de270..077acee 100644 --- a/ASN1-Tool/ASN1ImplicitTags.extension.st +++ b/ASN1-Tool/ASN1ImplicitTags.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #ASN1ImplicitTags } +Extension { #name : 'ASN1ImplicitTags' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ImplicitTags class >> readEncodedValue: anEncodedValue [ ^ anEncodedValue ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ImplicitTags class >> writeEncodedValue: aEncodedValue withTag: aTag [ "in an implicit tag environment the outer tag overwrites the inner tag " diff --git a/ASN1-Tool/ASN1MandatoryElementNotFound.class.st b/ASN1-Tool/ASN1MandatoryElementNotFound.class.st index be5a463..39beadf 100644 --- a/ASN1-Tool/ASN1MandatoryElementNotFound.class.st +++ b/ASN1-Tool/ASN1MandatoryElementNotFound.class.st @@ -1,10 +1,12 @@ Class { - #name : #ASN1MandatoryElementNotFound, - #superclass : #ASN1StructureError, - #category : 'ASN1-Tool-Exception' + #name : 'ASN1MandatoryElementNotFound', + #superclass : 'ASN1StructureError', + #category : 'ASN1-Tool-Exception', + #package : 'ASN1-Tool', + #tag : 'Exception' } -{ #category : #testing } +{ #category : 'testing' } ASN1MandatoryElementNotFound >> isResumable [ ^ true ] diff --git a/ASN1-Tool/ASN1ModelRoot.extension.st b/ASN1-Tool/ASN1ModelRoot.extension.st index 6bd6490..b1697fd 100644 --- a/ASN1-Tool/ASN1ModelRoot.extension.st +++ b/ASN1-Tool/ASN1ModelRoot.extension.st @@ -1,34 +1,34 @@ -Extension { #name : #ASN1ModelRoot } +Extension { #name : 'ASN1ModelRoot' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ModelRoot >> read: aTaggedValue [ ^ self modules first read: aTaggedValue inContext: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ModelRoot >> readFrom: anObject usingModule: aModule [ ^ aModule readFrom: anObject readStream inContext: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ModelRoot >> readFrom: anObject usingModule: aModule inContext: aContext [ ^ aModule readFrom: anObject readStream inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ModelRoot >> readFrom: anObject usingModuleNamed: aString [ ^ (self moduleNamed: aString) readFrom: anObject readStream inContext: self ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1ModelRoot >> resolveOidsWhile: aBlock [ ^ aBlock on: ASN1UnresolvedOid diff --git a/ASN1-Tool/ASN1Module.extension.st b/ASN1-Tool/ASN1Module.extension.st index e316672..e20f2a1 100644 --- a/ASN1-Tool/ASN1Module.extension.st +++ b/ASN1-Tool/ASN1Module.extension.st @@ -1,18 +1,18 @@ -Extension { #name : #ASN1Module } +Extension { #name : 'ASN1Module' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> encodeToByteArray: anObject [ ^ ASN1 encodeToByteArray: anObject usingType: self pdu ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> read: aTaggedValue [ ^ self read: aTaggedValue inContext: nil ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> read: aTaggedValue inContext: aContext [ ^ ASN1 read: aTaggedValue @@ -20,12 +20,12 @@ ASN1Module >> read: aTaggedValue inContext: aContext [ inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> readFrom: aStream [ ^ self readFrom: aStream inContext: nil ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> readFrom: aStream inContext: aContext [ ^ ASN1 readFrom: aStream @@ -33,14 +33,14 @@ ASN1Module >> readFrom: aStream inContext: aContext [ inContext: aContext ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> write: anObject [ ^ ASN1 write: anObject usingType: self pdu ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1Module >> write: anObject on: aStream [ ^ASN1 write: anObject diff --git a/ASN1-Tool/ASN1ObjectFactory.class.st b/ASN1-Tool/ASN1ObjectFactory.class.st index fc70697..93e3d70 100644 --- a/ASN1-Tool/ASN1ObjectFactory.class.st +++ b/ASN1-Tool/ASN1ObjectFactory.class.st @@ -1,38 +1,40 @@ Class { - #name : #ASN1ObjectFactory, - #superclass : #Object, + #name : 'ASN1ObjectFactory', + #superclass : 'Object', #instVars : [ 'asn1Model' ], - #category : 'ASN1-Tool-Visitor' + #category : 'ASN1-Tool-Visitor', + #package : 'ASN1-Tool', + #tag : 'Visitor' } -{ #category : #accessing } +{ #category : 'accessing' } ASN1ObjectFactory >> asn1Model [ ^ asn1Model ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ObjectFactory >> asn1Model: aModel [ asn1Model := aModel ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ObjectFactory >> moduleDefiningOid: anOid [ ^ self asn1Model moduleDefiningOid: anOid ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ObjectFactory >> newTypedCollection [ ^ ASN1AdaptiveTypeCollection new ] -{ #category : #creating } +{ #category : 'creating' } ASN1ObjectFactory >> newValueForTypeNamed: aString [ ^ (self asn1Model typeNamed: aString) newValue ] -{ #category : #lookup } +{ #category : 'lookup' } ASN1ObjectFactory >> typeNamed: aString [ ^ self asn1Model typeNamed: aString ] diff --git a/ASN1-Tool/ASN1PrimitiveType.extension.st b/ASN1-Tool/ASN1PrimitiveType.extension.st index 0e3963c..b86d3c2 100644 --- a/ASN1-Tool/ASN1PrimitiveType.extension.st +++ b/ASN1-Tool/ASN1PrimitiveType.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #ASN1PrimitiveType } +Extension { #name : 'ASN1PrimitiveType' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1PrimitiveType >> decodedValue: aByteArray [ ^ self newValue: ( self class decode: aByteArray ) ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1PrimitiveType >> encodedValue: anObject [ ^ ASN1EncodedPrimitiveValue new contents: (self class encode: anObject); diff --git a/ASN1-Tool/ASN1ReadVisitor.class.st b/ASN1-Tool/ASN1ReadVisitor.class.st index 5468952..af0f10d 100644 --- a/ASN1-Tool/ASN1ReadVisitor.class.st +++ b/ASN1-Tool/ASN1ReadVisitor.class.st @@ -1,15 +1,17 @@ Class { - #name : #ASN1ReadVisitor, - #superclass : #ASN1ModelVisitor, + #name : 'ASN1ReadVisitor', + #superclass : 'ASN1ModelVisitor', #instVars : [ 'skipErrors', 'currentTaggedValue', 'objectFactory' ], - #category : 'ASN1-Tool-Visitor' + #category : 'ASN1-Tool-Visitor', + #package : 'ASN1-Tool', + #tag : 'Visitor' } -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> checkOptionalAndDefault: anElement with: aCollection [ "check if the element is optional and add default value if available" anElement value isOptional ifFalse: [ @@ -24,50 +26,50 @@ ASN1ReadVisitor >> checkOptionalAndDefault: anElement with: aCollection [ aCollection privAt: anElement key put: anElement value defaultValue value ] ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> collectionClass [ ^ ASN1AdaptiveTypeCollection ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ReadVisitor >> defaultObjectFactory [ ^ ASN1ObjectFactory new ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ReadVisitor >> defaultValueClass [ ^ ASN1AdaptiveTypeObject ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> error: anError on: anObject [ skipErrors ifTrue: [ ^ anObject ] ifFalse: [ anError signal ] ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> externalClass [ ^ ASN1AdaptiveTypeExternal ] -{ #category : #'initialize-release' } +{ #category : 'initialize-release' } ASN1ReadVisitor >> initialize [ super initialize. skipErrors := false ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ReadVisitor >> objectFactory [ ^ objectFactory ] -{ #category : #acessing } +{ #category : 'acessing' } ASN1ReadVisitor >> objectFactory: anObjectFactory [ objectFactory := anObjectFactory ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> push: taggedValue during: aBlock [ | formerTaggedValue result | taggedValue ifNil: [ Error signal: 'cannot use nil as taggedValue' ]. @@ -78,12 +80,12 @@ ASN1ReadVisitor >> push: taggedValue during: aBlock [ ^ result ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> read: anEncodedType using: aType [ ^ self read: anEncodedType using: aType as: nil ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> read: anEncodedValue using: aType as: aClass [ ^ self @@ -91,27 +93,27 @@ ASN1ReadVisitor >> read: anEncodedValue using: aType as: aClass [ during: [ self visit: aType ] ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> read: anEncodedType usingModule: aModule [ ^ self read: anEncodedType using: aModule pdu as: nil ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1ReadVisitor >> read: anEncodedType usingModule: aModule as: aClass [ ^ self read: anEncodedType using: aModule pdu as: aClass ] -{ #category : #accessing } +{ #category : 'accessing' } ASN1ReadVisitor >> skipErrors: aBoolean [ skipErrors := aBoolean ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitAnyType: anAnyType [ ^ currentTaggedValue contents ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitChoiceType: aChoice [ | slot result value | value := aChoice newValue. @@ -129,7 +131,7 @@ ASN1ReadVisitor >> visitChoiceType: aChoice [ yourself ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitCollection: aCollection [ | value contentStream elementStream isExtended | isExtended := false. @@ -164,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: [ @@ -192,7 +195,7 @@ ASN1ReadVisitor >> visitCollection: aCollection [ ^ value ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitEnumeratedType: anEnumerated [ | number namedNumber | self flag: #hack. @@ -208,7 +211,7 @@ ASN1ReadVisitor >> visitEnumeratedType: anEnumerated [ ^ anEnumerated newValue contents: namedNumber name ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitExternalType: anExternalType [ | oid value | value := anExternalType newValue. @@ -235,24 +238,24 @@ ASN1ReadVisitor >> visitExternalType: anExternalType [ ^ value ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitObjectIdentifierType: anObjectIdentifier [ ^ self visitPrimitiveType: anObjectIdentifier ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitOpenType: anOpenType [ "an open type does not specify its kind. So we return the anonymous data. The data needs to be parsed in a second pass" ^ currentTaggedValue ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitPrimitiveType: aPrimitive [ ^ aPrimitive decodedValue: currentTaggedValue contents ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitTaggedType: aTaggedType [ "resolve the tagging environment over the tagged type because it is defined in the module defining the tagging environment (the type of the tagged type might be imported from another @@ -268,7 +271,7 @@ ASN1ReadVisitor >> visitTaggedType: aTaggedType [ value: basicValue ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1ReadVisitor >> visitTypedCollection: aCollection [ | seq | seq := self collectionClass new diff --git a/ASN1-Tool/ASN1StructureError.class.st b/ASN1-Tool/ASN1StructureError.class.st index 9a95699..e0aad3f 100644 --- a/ASN1-Tool/ASN1StructureError.class.st +++ b/ASN1-Tool/ASN1StructureError.class.st @@ -1,5 +1,7 @@ Class { - #name : #ASN1StructureError, - #superclass : #Error, - #category : 'ASN1-Tool-Exception' + #name : 'ASN1StructureError', + #superclass : 'Error', + #category : 'ASN1-Tool-Exception', + #package : 'ASN1-Tool', + #tag : 'Exception' } diff --git a/ASN1-Tool/ASN1TagEnvironment.extension.st b/ASN1-Tool/ASN1TagEnvironment.extension.st index f3cf698..a5b441e 100644 --- a/ASN1-Tool/ASN1TagEnvironment.extension.st +++ b/ASN1-Tool/ASN1TagEnvironment.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #ASN1TagEnvironment } +Extension { #name : 'ASN1TagEnvironment' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1TagEnvironment class >> encode: anObject using: aType [ self subclassResponsibility ] diff --git a/ASN1-Tool/ASN1TaggedType.extension.st b/ASN1-Tool/ASN1TaggedType.extension.st index b477eff..4b7f9d4 100644 --- a/ASN1-Tool/ASN1TaggedType.extension.st +++ b/ASN1-Tool/ASN1TaggedType.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #ASN1TaggedType } +Extension { #name : 'ASN1TaggedType' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1TaggedType >> encodeTaggedValue: aTaggedValue [ "a tagged type consists of an inner tag and an outer tag. While encoding the tag environment indicates if both tags are encoded (explicit) or if @@ -11,7 +11,7 @@ ASN1TaggedType >> encodeTaggedValue: aTaggedValue [ outerTag: tag ] -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } ASN1TaggedType >> readEncodedValue: aTaggedValue [ ^ self type decodeTaggedValue: aTaggedValue diff --git a/ASN1-Tool/ASN1UnexpectedType.class.st b/ASN1-Tool/ASN1UnexpectedType.class.st index 50f1fa4..ce65a78 100644 --- a/ASN1-Tool/ASN1UnexpectedType.class.st +++ b/ASN1-Tool/ASN1UnexpectedType.class.st @@ -1,5 +1,7 @@ Class { - #name : #ASN1UnexpectedType, - #superclass : #ASN1StructureError, - #category : 'ASN1-Tool-Exception' + #name : 'ASN1UnexpectedType', + #superclass : 'ASN1StructureError', + #category : 'ASN1-Tool-Exception', + #package : 'ASN1-Tool', + #tag : 'Exception' } diff --git a/ASN1-Tool/ASN1WriteVisitor.class.st b/ASN1-Tool/ASN1WriteVisitor.class.st index 9f4f27f..90bf356 100644 --- a/ASN1-Tool/ASN1WriteVisitor.class.st +++ b/ASN1-Tool/ASN1WriteVisitor.class.st @@ -1,18 +1,27 @@ Class { - #name : #ASN1WriteVisitor, - #superclass : #ASN1ModelVisitor, + #name : 'ASN1WriteVisitor', + #superclass : 'ASN1ModelVisitor', #instVars : [ - 'currentValue' + 'currentValue', + 'skipAddedDefaults' ], - #category : 'ASN1-Tool-Visitor' + #category : 'ASN1-Tool-Visitor', + #package : 'ASN1-Tool', + #tag : 'Visitor' } -{ #category : #exceptions } +{ #category : 'initialization' } +ASN1WriteVisitor >> initialize [ + super initialize. + skipAddedDefaults := true +] + +{ #category : 'exceptions' } ASN1WriteVisitor >> mandatoryElementNotFound [ ASN1MandatoryElementNotFound signal ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } ASN1WriteVisitor >> push: anObject during: aBlock [ | formerValue | anObject ifNil: [ Error signal: 'cannot push nil onto stack' ]. @@ -21,7 +30,12 @@ ASN1WriteVisitor >> push: anObject during: aBlock [ ^aBlock ensure: [ currentValue := formerValue ] ] -{ #category : #visiting } +{ #category : 'accessing' } +ASN1WriteVisitor >> skipAddedDefaults [ + skipAddedDefaults := true +] + +{ #category : 'visiting' } ASN1WriteVisitor >> visit: aType [ (aType isNil ifTrue: [ Error signal: 'type cannot be nil' ]). "we need either a ASN.1 value object or an already encoded value" @@ -32,7 +46,7 @@ ASN1WriteVisitor >> visit: aType [ ^ super visit: aType ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitChoiceType: aChoice [ | key type | key := currentValue keys first. @@ -42,13 +56,13 @@ ASN1WriteVisitor >> visitChoiceType: aChoice [ during: [ self visit: type ]. ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitEnumeratedType: anEnumerated [ ^ currentValue encodedValue ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitExternalType: anExternalType [ | encoded module | encoded := ASN1EncodedConstructedValue new @@ -67,13 +81,13 @@ ASN1WriteVisitor >> visitExternalType: anExternalType [ ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitObjectIdentifierType: anObjectIdentifier [ ^ anObjectIdentifier encodedValue: currentValue contents. ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitOpenType: anOpenType [ self flag: #hack. "oid := ASN1OpenTypeDefinition signal." @@ -84,13 +98,13 @@ ASN1WriteVisitor >> visitOpenType: anOpenType [ during: [self visit: currentValue type ] ] ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitPrimitiveType: aPrimitiveType [ (currentValue type class = aPrimitiveType class) ifFalse: [ Error signal: 'primitive types do not match' ]. ^ currentValue encodedValue "aPrimitive encodedValue: currentValue value" ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitSequenceType: aSequence [ | encoded object | encoded := ASN1EncodedConstructedValue new @@ -99,22 +113,23 @@ 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 ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitTaggedType: aTaggedType [ "tag the type based on the existance of an explicit tag and itsaTaggedType tag environment" @@ -124,7 +139,7 @@ ASN1WriteVisitor >> visitTaggedType: aTaggedType [ during: [ self visit: aTaggedType type ]) ] -{ #category : #visiting } +{ #category : 'visiting' } ASN1WriteVisitor >> visitTypedCollection: aTypedSequence [ "All elements that are on the top of the stack are encoded with the type of the typed sequence" @@ -138,14 +153,14 @@ ASN1WriteVisitor >> visitTypedCollection: aTypedSequence [ ^ encoded ] -{ #category : #writing } +{ #category : 'writing' } ASN1WriteVisitor >> write: anObject using: anAsn1Type [ currentValue := anObject. ^ self visit: anAsn1Type ] -{ #category : #writing } +{ #category : 'writing' } ASN1WriteVisitor >> write: anObject usingModule: aModule [ currentValue := anObject. ^ self visit: aModule pdu diff --git a/ASN1-Tool/Object.extension.st b/ASN1-Tool/Object.extension.st index 20d081c..7774404 100644 --- a/ASN1-Tool/Object.extension.st +++ b/ASN1-Tool/Object.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #Object } +Extension { #name : 'Object' } -{ #category : #'*asn1-tool' } +{ #category : '*asn1-tool' } Object >> basicValue [ ^ self ] diff --git a/ASN1-Tool/package.st b/ASN1-Tool/package.st index bc9851b..1f1ed1e 100644 --- a/ASN1-Tool/package.st +++ b/ASN1-Tool/package.st @@ -1 +1 @@ -Package { #name : #'ASN1-Tool' } +Package { #name : 'ASN1-Tool' }