2011-03-29 19:25:20 +00:00
|
|
|
"
|
|
|
|
(C) 2011 by Holger Hans Peter Freyther
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"
|
|
|
|
|
|
|
|
Object subclass: BERTag [
|
|
|
|
| classType tagValue constructed |
|
|
|
|
<category: 'osmo-asn1'>
|
|
|
|
<comment: 'I am a TAG as of X.690'>
|
|
|
|
|
|
|
|
BERTag class >> classUniversal [
|
|
|
|
<category: 'class'>
|
|
|
|
^ 0
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> classApplication [
|
|
|
|
<category: 'class'>
|
|
|
|
^ 1
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> classContext [
|
|
|
|
<category: 'class'>
|
|
|
|
^ 2
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> classPrivate [
|
|
|
|
<category: 'class'>
|
|
|
|
^ 3
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> new [
|
|
|
|
<category: 'creation'>
|
|
|
|
^ super new initialize
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> parseFrom: aStream [
|
|
|
|
<category: 'creation'>
|
|
|
|
^ self new
|
|
|
|
parseFrom: aStream;
|
|
|
|
yourself
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> fromTuple: aTuple [
|
|
|
|
<category: 'creation'>
|
|
|
|
^ self new
|
|
|
|
fromTuple: aTuple;
|
|
|
|
yourself
|
|
|
|
]
|
|
|
|
|
2011-03-29 19:41:01 +00:00
|
|
|
BERTag class >> endOfContents [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 0)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> boolean [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 1)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> integer [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 2)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> octetString [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 4)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> null [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 5)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> enumerated [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 false 10)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> sequence [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 true 16)
|
|
|
|
]
|
|
|
|
|
|
|
|
BERTag class >> set [
|
|
|
|
<category: 'x690 types'>
|
|
|
|
^ self fromTuple: #(0 true 17)
|
|
|
|
]
|
|
|
|
|
2011-03-29 19:25:20 +00:00
|
|
|
initialize [
|
|
|
|
<category: 'init'>
|
|
|
|
classType := BERTag classUniversal.
|
|
|
|
tagValue := 0.
|
|
|
|
constructed := false.
|
|
|
|
]
|
|
|
|
|
|
|
|
parseExtendedTag: aStream [
|
|
|
|
<category: 'decoding'>
|
|
|
|
|
|
|
|
^ self error: 'Extended tags are not implemented yet'.
|
|
|
|
]
|
|
|
|
|
|
|
|
parseFrom: aStream [
|
|
|
|
| tmp |
|
|
|
|
<category: 'decoding'>
|
|
|
|
|
|
|
|
tmp := aStream next.
|
|
|
|
classType := (tmp bitAnd: 16rC0) bitShift: -6.
|
|
|
|
constructed := (tmp bitAnd: 16r20) > 0.
|
|
|
|
tagValue := tmp bitAnd: 16r1F.
|
|
|
|
|
|
|
|
"This is an extended tag"
|
|
|
|
(tagValue = 16r1F) ifTrue: [
|
|
|
|
self parseExtendedTag: aStream.
|
|
|
|
].
|
|
|
|
]
|
|
|
|
|
|
|
|
fromTuple: aTuple [
|
|
|
|
<category: 'decoding'>
|
|
|
|
|
|
|
|
classType := aTuple first bitAnd: 16r3.
|
2011-03-29 19:41:01 +00:00
|
|
|
constructed := aTuple second.
|
2011-03-29 19:25:20 +00:00
|
|
|
tagValue := aTuple third.
|
|
|
|
]
|
|
|
|
|
|
|
|
writeExtendedTag: aStream [
|
|
|
|
<category: 'encoding'>
|
|
|
|
self error: 'Cannot encode extended tag.'
|
|
|
|
]
|
|
|
|
|
|
|
|
writeOn: aStream [
|
|
|
|
<category: 'encoding'>
|
|
|
|
tagValue >= 16r1F
|
|
|
|
ifTrue: [self writeExtendedTag: aStream.]
|
|
|
|
ifFalse: [| tag |
|
|
|
|
tag := classType bitShift: 6.
|
|
|
|
self isConstructed ifTrue: [tag := tag bitOr: 16r20].
|
|
|
|
tag := tag bitOr: self tagValue.
|
|
|
|
aStream nextPut: tag.
|
|
|
|
].
|
|
|
|
]
|
|
|
|
|
|
|
|
classType [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ classType
|
|
|
|
]
|
|
|
|
|
|
|
|
isConstructed [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ constructed
|
|
|
|
]
|
|
|
|
|
|
|
|
isPrimitive [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ self isConstructed not
|
|
|
|
]
|
|
|
|
|
|
|
|
tagValue [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ tagValue
|
|
|
|
]
|
|
|
|
|
|
|
|
asTuple [
|
|
|
|
<category: 'conversion'>
|
2011-03-29 19:41:01 +00:00
|
|
|
^ Array with: self classType with: self isConstructed with: self tagValue.
|
2011-03-29 19:25:20 +00:00
|
|
|
]
|
|
|
|
]
|