Module: Cul::Handles::Hdl
- Included in:
- BaseMessage, BaseResponse, ChallengeAnswerRequest, Client, DH, DeleteHandleRequest, HandleValue, RemoveValueRequest, SessionSetupRequest
- Defined in:
- lib/cul/handles/hdl.rb
Defined Under Namespace
Classes: UnsignedByte, UnsignedInt, UnsignedShort
Constant Summary collapse
- MSG_FLAG_AUTH =
OpFlag masks
0x80
- MSG_FLAG_CERT =
don’t use cache, use only primaries
0x40
- MSG_FLAG_ENCR =
asks server to sign responses
0x20
- MSG_FLAG_RECU =
asks server to encrypt responses
0x10
- MSG_FLAG_CACR =
server should try and resolve handle if not found
0x08
- MSG_FLAG_CONT =
responses should be signed by cache
0x04
- MSG_FLAG_KPAL =
there are more parts to this message
0x02
- MSG_FLAG_PUBL =
keep the socket open for more requests
0x01
- MSG_FLAG_RRDG =
resolution requests should only return public vals
0x80
- MSG_FLAG_AUTH_INDEX =
responses should include a digest of the request
0
- MSG_FLAG_CERT_INDEX =
0
- MSG_FLAG_ENCR_INDEX =
0
- MSG_FLAG_RECU_INDEX =
0
- MSG_FLAG_CACR_INDEX =
0
- MSG_FLAG_CONT_INDEX =
0
- MSG_FLAG_KPAL_INDEX =
0
- MSG_FLAG_PUBL_INDEX =
0
- MSG_FLAG_RRDG_INDEX =
1
- ENV_FLAG_COMPRESSED =
MessageFlag masks
0x80
- ENV_FLAG_ENCRYPTED =
0x40
- ENV_FLAG_TRUNCATED =
0x20
- OC_RESERVED =
OpCode values
0
- OC_RESOLUTION =
1
- OC_GET_SITEINFO =
2
- OC_CREATE_HANDLE =
100
- OC_DELETE_HANDLE =
101
- OC_ADD_VALUE =
102
- OC_REMOVE_VALUE =
103
- OC_MODIFY_VALUE =
104
- OC_LIST_HANDLE =
105
- OC_LIST_NA =
106
- OC_CHALLENGE_RESPONSE =
200
- OC_VERIFY_RESPONSE =
201
- OC_SESSION_SETUP =
400
- OC_SESSION_TERMINATE =
401
- OC_SESSION_EXCHANGEKEY =
402
- RC_RESERVED =
ResponseCode values
0
- RC_SUCCESS =
1
- RC_ERROR =
2
- RC_SERVER_BUSY =
3
- RC_PROTOCOL_ERROR =
4
- RC_OPERATION_DENIED =
5
- RC_RECUR_LIMIT_EXCEEDED =
6
- RC_HANDLE_NOT_FOUND =
100
- RC_HANDLE_ALREADY_EXIST =
101
- RC_INVALID_HANDLE =
102
- RC_VALUE_NOT_FOUND =
200
- RC_VALUE_ALREADY_EXIST =
201
- RC_VALUE_INVALID =
202
- RC_EXPIRED_SITE_INFO =
300
- RC_SERVER_NOT_RESP =
301
- RC_SERVICE_REFERRAL =
302
- RC_NA_DELEGATE =
303
- RC_NOT_AUTHORIZED =
400
- RC_ACCESS_DENIED =
401
- RC_AUTHEN_NEEDED =
402
- RC_AUTHEN_FAILED =
403
- RC_INVALID_CREDENTIAL =
404
- RC_AUTHEN_TIMEOUT =
405
- RC_UNABLE_TO_AUTHEN =
406
- RC_SESSION_TIMEOUT =
500
- RC_SESSION_FAILED =
501
- RC_NO_SESSION_KEY =
502
- RC_SESSION_NO_SUPPORT =
503
- RC_SESSION_KEY_INVALID =
504
- RC_TRYING =
900
- RC_FORWARDED =
901
- RC_QUEUED =
902
- PERM_ADD_HANDLE =
handle value admin permissions
0x0001
- PERM_DELETE_HANDLE =
0x0002
- PERM_ADD_NA =
0x0004
- PERM_DELETE_NA =
0x0008
- PERM_MODIFY_VALUE =
0x0010
- PERM_REMOVE_VALUE =
0x0020
- PERM_ADD_VALUE =
0x0040
- PERM_MODIFY_ADMIN =
0x0080
- PERM_REMOVE_ADMIN =
0x0100
- PERM_ADD_ADMIN =
0x0200
- PERM_READ_VALUE =
0x0400
- PERM_LIST_HDLS =
0x0800
- PERM_ALL =
0x0fff
- INDEX_ADMIN_HANDLE =
standard handle indices
100
- INDEX_MAINTAINER_HANDLE =
index for create/delete/super admin
101
- INDEX_AUTH =
index for modify/update admin
300
Instance Method Summary collapse
- #asBytes(val) ⇒ Object
- #calculateValueLen(values, offset = 0) ⇒ Object
- #convert16t8(data) ⇒ Object
- #decodeAdminData(data) ⇒ Object
- #encodeAdminData(adminHandle, permissions, index) ⇒ Object
- #fromBytes(data) ⇒ Object
- #readByteArray(data, offset = 0) ⇒ Object
- #readIntArray(data, offset = 0) ⇒ Object
- #readProtocolString(data, offset = 0) ⇒ Object
- #toProtocolString(data) ⇒ Object
Instance Method Details
#asBytes(val) ⇒ Object
156 157 158 |
# File 'lib/cul/handles/hdl.rb', line 156 def asBytes(val) [(val&0xff000000)>>24,(val&0xff0000)>>16,(val&0xff00)>>8,val&0xff] end |
#calculateValueLen(values, offset = 0) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/cul/handles/hdl.rb', line 203 def calculateValueLen(values,offset=0) origOffset = offset offset = offset + 14 # index - 4 bytes; timestamp - 4 bytes; ttlType - 1 byte; ttl - 4 bytes; permissions - 1 byte fieldLen = fromBytes( values[offset...offset+4]) # type field offset = offset + 4 + fieldLen fieldLen = fromBytes( values[offset...offset+4]) # data field offset = offset + 4 + fieldLen fieldLen = fromBytes( values[offset...offset+4]) # references (number of) offset = offset + 4 + fieldLen for i in (1..fieldLen) # each reference - hdl length + hdl + index refLen = fromBytes( values[offset...offset+4]) offset = offset + 4 + refLen + 4 end return offset - origOffset end |
#convert16t8(data) ⇒ Object
238 239 240 241 |
# File 'lib/cul/handles/hdl.rb', line 238 def convert16t8(data) # first split into bytes [] end |
#decodeAdminData(data) ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'lib/cul/handles/hdl.rb', line 222 def decodeAdminData(data) = fromBytes(data[0..1]) arrayInfo = readByteArray(data[2...-1]) offset = 2 + arrayInfo[0] adminHandle = arrayInfo[1].pack('U*') index = fromBytes(data[offset..offset+3]) return {'permissions' => , 'handle' => adminHandle, 'index' => index} end |
#encodeAdminData(adminHandle, permissions, index) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/cul/handles/hdl.rb', line 230 def encodeAdminData(adminHandle, , index) result = asBytes()[2..3] hbytes = adminHandle.unpack('U*') result.concat(asBytes(hbytes.length)) result.concat(hbytes) result.concat(asBytes(index)) result end |
#fromBytes(data) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/cul/handles/hdl.rb', line 159 def fromBytes(data) if(data.nil?) return 0 end result = 0 shift = data.length - 1 data.each{|byte| digit = UnsignedByte.fromBytes(byte) result = result + (digit << (8*shift)) shift = shift - 1 } return result end |
#readByteArray(data, offset = 0) ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/cul/handles/hdl.rb', line 189 def readByteArray(data,offset=0) bytes = fromBytes(data[offset...offset+4]) octetsRead = 4 + bytes start = offset + 4 result = data[start...(start+bytes)] return [octetsRead,result] end |
#readIntArray(data, offset = 0) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/cul/handles/hdl.rb', line 196 def readIntArray(data,offset=0) ints = fromBytes(data[offset...offset+4]) octetsRead = 4 + (4*ints) start = offset + 4 result = data[start...(offset+octetsRead)] return [octetsRead,result] end |
#readProtocolString(data, offset = 0) ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cul/handles/hdl.rb', line 179 def readProtocolString(data,offset=0) octetsRead = 4 length = fromBytes(data[offset...offset+4]) pstring = "" if length > 0 pstring = data[offset+4...offset+4+length].pack('C*') octetsRead = octetsRead + length end return [octetsRead,pstring] end |
#toProtocolString(data) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/cul/handles/hdl.rb', line 172 def toProtocolString(data) dataBytes = data.unpack('U*').pack('U*').unpack('C*') length = dataBytes.length result = asBytes(length) result.concat(dataBytes) return result end |