#NEWLINE# @ staticmethod #NEWLINE# def parse_request( request ) : #NEWLINE# #INDENT# '\n        This method contains logic to detect a v1 and beyond request and\n        differentiate it from a version 0 request, which is just an ascii\n        username. While all v1 requests are also valid usernames (the curse\n        and blessing of base64 encoding) it is pretty unlikely that a username\n        happens to also decode to a valid msgpack message with the correct\n        magic values.\n\n        @return a tuple containing username then version\n        ' #NEWLINE# if ( ( len ( request ) % 4 ) == 1 ) : #NEWLINE# #INDENT# return ( request , 0 ) #NEWLINE# #UNINDENT# binary = ssh . base64url_decode ( request ) #NEWLINE# if ( len ( binary ) < 4 ) : #NEWLINE# #INDENT# return ( request , 0 ) #NEWLINE# #UNINDENT# if ( ( ord ( binary [ 0 ] ) > 4 ) or ( binary [ 1 ] != 'q' ) ) : #NEWLINE# #INDENT# return ( request , 0 ) #NEWLINE# #UNINDENT# b = ord ( binary [ 2 ] ) #NEWLINE# if ( ( ( b < 161 ) or ( b > 191 ) ) and ( b != 217 ) ) : #NEWLINE# #INDENT# return ( request , 0 ) #NEWLINE# #UNINDENT# if ( binary == 217 ) : #NEWLINE# #INDENT# username_start = 4 #NEWLINE# username_len = ord ( binary [ 3 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# username_start = 3 #NEWLINE# username_len = ( ord ( binary [ 2 ] ) & 31 ) #NEWLINE# #UNINDENT# if ( ( len ( binary ) - username_start ) < username_len ) : #NEWLINE# #INDENT# return ( request , 0 ) #NEWLINE# #UNINDENT# return ( binary [ username_start : ( username_start + username_len ) ] , 1 )