/ / /   M i s c e l l a n e o u s   u t i l i t y   f u n c t i o n s   u s e d   a c r o s s   t h e   p a c k a g e . 
 
 / / / 
 
 / /   T i m e - s t a m p :   < F r i d a y   2 0 2 5 - 1 0 - 2 4   0 8 : 5 1 : 5 4   + 1 1 0 0   G r a h a m   W i l l i a m s > 
 
 / / / 
 
 / / /   C o p y r i g h t   ( C )   2 0 2 4 ,   S o f t w a r e   I n n o v a t i o n   I n s t i t u t e ,   A N U . 
 
 / / / 
 
 / / /   L i c e n s e d   u n d e r   t h e   M I T   L i c e n s e   ( t h e   " L i c e n s e " ) . 
 
 / / / 
 
 / / /   L i c e n s e :   h t t p s : / / c h o o s e a l i c e n s e . c o m / l i c e n s e s / m i t / . 
 
 / / 
 
 / /   P e r m i s s i o n   i s   h e r e b y   g r a n t e d ,   f r e e   o f   c h a r g e ,   t o   a n y   p e r s o n   o b t a i n i n g   a   c o p y 
 
 / /   o f   t h i s   s o f t w a r e   a n d   a s s o c i a t e d   d o c u m e n t a t i o n   f i l e s   ( t h e   " S o f t w a r e " ) ,   t o   d e a l 
 
 / /   i n   t h e   S o f t w a r e   w i t h o u t   r e s t r i c t i o n ,   i n c l u d i n g   w i t h o u t   l i m i t a t i o n   t h e   r i g h t s 
 
 / /   t o   u s e ,   c o p y ,   m o d i f y ,   m e r g e ,   p u b l i s h ,   d i s t r i b u t e ,   s u b l i c e n s e ,   a n d / o r   s e l l 
 
 / /   c o p i e s   o f   t h e   S o f t w a r e ,   a n d   t o   p e r m i t   p e r s o n s   t o   w h o m   t h e   S o f t w a r e   i s 
 
 / /   f u r n i s h e d   t o   d o   s o ,   s u b j e c t   t o   t h e   f o l l o w i n g   c o n d i t i o n s : 
 
 / / 
 
 / /   T h e   a b o v e   c o p y r i g h t   n o t i c e   a n d   t h i s   p e r m i s s i o n   n o t i c e   s h a l l   b e   i n c l u d e d   i n 
 
 / /   a l l   c o p i e s   o r   s u b s t a n t i a l   p o r t i o n s   o f   t h e   S o f t w a r e . 
 
 / / 
 
 / /   T H E   S O F T W A R E   I S   P R O V I D E D   " A S   I S " ,   W I T H O U T   W A R R A N T Y   O F   A N Y   K I N D ,   E X P R E S S   O R 
 
 / /   I M P L I E D ,   I N C L U D I N G   B U T   N O T   L I M I T E D   T O   T H E   W A R R A N T I E S   O F   M E R C H A N T A B I L I T Y , 
 
 / /   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E   A N D   N O N I N F R I N G E M E N T .   I N   N O   E V E N T   S H A L L   T H E 
 
 / /   A U T H O R S   O R   C O P Y R I G H T   H O L D E R S   B E   L I A B L E   F O R   A N Y   C L A I M ,   D A M A G E S   O R   O T H E R 
 
 / /   L I A B I L I T Y ,   W H E T H E R   I N   A N   A C T I O N   O F   C O N T R A C T ,   T O R T   O R   O T H E R W I S E ,   A R I S I N G   F R O M , 
 
 / /   O U T   O F   O R   I N   C O N N E C T I O N   W I T H   T H E   S O F T W A R E   O R   T H E   U S E   O R   O T H E R   D E A L I N G S   I N   T H E 
 
 / /   S O F T W A R E . 
 
 / / / 
 
 / / /   A u t h o r s :   A n u s h k a   V i d a n a g e ,   D a w e i   C h e n ,   Z h e y u a n   X u 
 
 
 
 l i b r a r y ; 
 
 
 
 i m p o r t   ' d a r t : c o n v e r t ' ; 
 
 
 
 i m p o r t   ' p a c k a g e : f l u t t e r / f o u n d a t i o n . d a r t '   s h o w   d e b u g P r i n t ; 
 
 
 
 i m p o r t   ' p a c k a g e : c r y p t o / c r y p t o . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : e n c r y p t e r _ p l u s / e n c r y p t e r _ p l u s . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : f a s t _ r s a / f a s t _ r s a . d a r t '   s h o w   K e y P a i r ; 
 
 i m p o r t   ' p a c k a g e : i n t l / i n t l . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : j w t _ d e c o d e r / j w t _ d e c o d e r . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : p a t h / p a t h . d a r t '   a s   p a t h ; 
 
 i m p o r t   ' p a c k a g e : r d f l i b / r d f l i b . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d _ a u t h / s o l i d _ a u t h . d a r t '   s h o w   g e n D p o p T o k e n ,   l o g o u t ; 
 
 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / a p i / r e s t _ a p i . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / c o n s t a n t s / c o m m o n . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / c o n s t a n t s / p a t h _ t y p e . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / c o n s t a n t s / s c h e m a . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / c o n s t a n t s / w e b _ a c l . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / r e v o k e _ p e r m i s s i o n _ t o _ r e c i p i e n t s . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / a p p _ i n f o . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / a u t h d a t a _ m a n a g e r . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / e x c e p t i o n s . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / k e y _ m a n a g e r . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / p e r m i s s i o n . d a r t ' ; 
 
 i m p o r t   ' p a c k a g e : s o l i d p o d / s r c / s o l i d / u t i l s / r d f . d a r t ' ; 
 
 
 
 / / /   G l o b a l   c a l l b a c k   f o r   c l e a r i n g   a p p l i c a t i o n - s p e c i f i c   c a c h e s   d u r i n g   l o g o u t . 
 
 / / /   A p p s   s h o u l d   r e g i s t e r   t h e i r   c a c h e   c l e a r i n g   l o g i c   h e r e . 
 
 / / /   T h i s   e n s u r e s   c a c h e s   a r e   c l e a r e d   B E F O R E   a n y   b l o c k i n g   n e t w o r k   o p e r a t i o n s . 
 
 F u t u r e < v o i d >   F u n c t i o n ( ) ?   _ o n L o g o u t C l e a r C a c h e s ; 
 
 
 
 / / /   R e g i s t e r   a   c a l l b a c k   t o   c l e a r   a p p l i c a t i o n - s p e c i f i c   c a c h e s   d u r i n g   l o g o u t . 
 
 / / /   T h i s   c a l l b a c k   w i l l   b e   i n v o k e d   B E F O R E   t h e   O A u t h 2   l o g o u t   e n d p o i n t   c a l l , 
 
 / / /   p r e v e n t i n g   r a c e   c o n d i t i o n s   w h e r e   c a c h e d   d a t a   m i g h t   b e   v i s i b l e   d u r i n g   l o g o u t . 
 
 v o i d   r e g i s t e r L o g o u t C a c h e C a l l b a c k ( F u t u r e < v o i d >   F u n c t i o n ( )   c a l l b a c k )   { 
 
     _ o n L o g o u t C l e a r C a c h e s   =   c a l l b a c k ; 
 
 } 
 
 
 
 / /   s o l i d - e n c r y p t   u s e s   u n e n c r y p t e d   l o c a l   s t o r a g e   a n d   r e f e r s   t o   h t t p :   / / y a r r a b a h . n e t /   f o r   p r e d i c a t e s   d e f i n i t i o n , 
 
 / /   d o   n o t   u s e   i t   b e f o r e   i t   i s   u p d a t e d   ( s a m e   a s   w h a t   t h e   g u r r i n y   p r o j e c t   d o e s ) 
 
 / /   i m p o r t   ' p a c k a g e : s o l i d _ e n c r y p t / s o l i d _ e n c r y p t . d a r t '   a s   s o l i d _ e n c r y p t ; 
 
 
 
 / / /   W r i t e   t h e   g i v e n   [ k e y ] ,   [ v a l u e ]   p a i r   t o   t h e   s e c u r e   s t o r a g e . 
 
 / / / 
 
 / / /   I f   [ k e y ]   a l r e a d y   e x i s i t s   t h e n   d e l e t e   t h a t   f i r s t   a n d   t h e n 
 
 / / /   w r i t e   a g a i n . 
 
 
 
 F u t u r e < v o i d >   w r i t e T o S e c u r e S t o r a g e ( S t r i n g   k e y ,   S t r i n g   v a l u e )   a s y n c   { 
 
     f i n a l   i s K e y E x i s t   =   a w a i t   s e c u r e S t o r a g e . c o n t a i n s K e y ( 
 
         k e y :   k e y , 
 
     ) ; 
 
 
 
     / /   S i n c e   w r i t e ( )   m e t h o d   d o e s   n o t   a u t o m a t i c a l l y   o v e r w r i t e   a n   e x i s t i n g   v a l u e . 
 
     / /   T o   o v e r w r i t e   a n   e x i s t i n g   v a l u e ,   c a l l   d e l e t e ( )   f i r s t . 
 
 
 
     i f   ( i s K e y E x i s t )   { 
 
         a w a i t   s e c u r e S t o r a g e . d e l e t e ( 
 
             k e y :   k e y , 
 
         ) ; 
 
     } 
 
 
 
     a w a i t   s e c u r e S t o r a g e . w r i t e ( 
 
         k e y :   k e y , 
 
         v a l u e :   v a l u e , 
 
     ) ; 
 
 } 
 
 
 
 / / /   E n c r y p t   d a t a   u s i n g   A E S   w i t h   t h e   s p e c i f i e d   k e y 
 
 S t r i n g   e n c r y p t D a t a ( S t r i n g   d a t a ,   K e y   k e y ,   I V   i v ,   { A E S M o d e   m o d e   =   A E S M o d e . s i c } )   = > 
 
         E n c r y p t e r ( A E S ( k e y ,   m o d e :   m o d e ) ) . e n c r y p t ( d a t a ,   i v :   i v ) . b a s e 6 4 ; 
 
 
 
 / / /   D e c r y p t   a   c i p h e r t e x t   v a l u e 
 
 S t r i n g   d e c r y p t D a t a ( 
 
     S t r i n g   e n c D a t a , 
 
     K e y   k e y , 
 
     I V   i v ,   { 
 
     A E S M o d e   m o d e   =   A E S M o d e . s i c , 
 
 } )   = > 
 
         E n c r y p t e r ( A E S ( k e y ,   m o d e :   m o d e ) ) . d e c r y p t ( E n c r y p t e d . f r o m 6 4 ( e n c D a t a ) ,   i v :   i v ) ; 
 
 
 
 / / /   L o a d   a n d   p a r s e   a   p r i v a t e   T T L   f i l e   f r o m   P O D 
 
 F u t u r e < M a p < S t r i n g ,   d y n a m i c > >   l o a d P r v T T L ( S t r i n g   f i l e U r l )   a s y n c   { 
 
     / /   f i n a l   f i l e U r l   =   a w a i t   g e t F i l e U r l ( f i l e P a t h ) ; 
 
     t r y   { 
 
         i f   ( a w a i t   c h e c k R e s o u r c e S t a t u s ( f i l e U r l )   = =   R e s o u r c e S t a t u s . e x i s t )   { 
 
             f i n a l   r a w C o n t e n t   =   a w a i t   f e t c h P r v F i l e ( f i l e U r l ) ; 
 
             r e t u r n   p a r s e T t l C o n t e n t ( r a w C o n t e n t ) ; 
 
         }   e l s e   { 
 
             r e t u r n   { } ; 
 
         } 
 
     }   o n   E x c e p t i o n   c a t c h   ( e )   { 
 
         t h r o w   E x c e p t i o n ( e ) ; 
 
     } 
 
 } 
 
 
 
 / / /   R e a d   t h e   e n c r y p t i o n   k e y   f i l e   c o n t e n t   f o r   d i s p l a y   p u r p o s e s . 
 
 / / / 
 
 / / /   T h i s   f u n c t i o n   d i r e c t l y   r e a d s   t h e   e n c r y p t i o n   k e y   f i l e   w i t h o u t   u s i n g   r e a d P o d , 
 
 / / /   m a k i n g   i t   s u i t a b l e   f o r   a c c e s s i n g   f i l e s   o u t s i d e   t h e   a p p n a m e / d a t a   d i r e c t o r y . 
 
 / / / 
 
 / / /   R e t u r n s   t h e   r a w   T T L   c o n t e n t   o f   t h e   e n c r y p t i o n   k e y   f i l e . 
 
 F u t u r e < S t r i n g >   r e a d E n c r y p t i o n K e y C o n t e n t ( )   a s y n c   { 
 
     f i n a l   e n c K e y P a t h   =   a w a i t   g e t E n c K e y P a t h ( ) ; 
 
     f i n a l   e n c K e y U r l   =   a w a i t   g e t F i l e U r l ( e n c K e y P a t h ) ; 
 
 
 
     t r y   { 
 
         i f   ( a w a i t   c h e c k R e s o u r c e S t a t u s ( e n c K e y U r l )   = =   R e s o u r c e S t a t u s . e x i s t )   { 
 
             r e t u r n   a w a i t   f e t c h P r v F i l e ( e n c K e y U r l ) ; 
 
         }   e l s e   { 
 
             t h r o w   E x c e p t i o n ( ' E n c r y p t i o n   k e y   f i l e   d o e s   n o t   e x i s t   a t :   $ e n c K e y P a t h ' ) ; 
 
         } 
 
     }   o n   E x c e p t i o n   c a t c h   ( e )   { 
 
         t h r o w   E x c e p t i o n ( ' F a i l e d   t o   r e a d   e n c r y p t i o n   k e y   f i l e :   $ e ' ) ; 
 
     } 
 
 } 
 
 
 
 / / /   G e n e r a t e s   a   p u b l i c   k e y   b l o c k   f r o m   a   g i v e n   k e y   c o n t e n t . 
 
 S t r i n g   g e n P u b K e y S t r ( S t r i n g   p u b K e y C o n t e n t )   = > 
 
         ' ' ' - - - - - B E G I N   R S A   P U B L I C   K E Y - - - - - \ n $ p u b K e y C o n t e n t \ n - - - - - E N D   R S A   P U B L I C   K E Y - - - - - ' ' ' ; 
 
 
 
 / / /   G e t   u n i q u e   b i t   o f   t h e   w e b I d 
 
 S t r i n g   g e t U n i q u e S t r W e b I d ( S t r i n g   w e b I d )   { 
 
     v a r   u n i q u e S t r   =   w e b I d . r e p l a c e A l l ( ' h t t p s : / / ' ,   ' ' ) ; 
 
     u n i q u e S t r   =   u n i q u e S t r . r e p l a c e A l l ( ' h t t p : / / ' ,   ' ' ) ; 
 
     u n i q u e S t r   =   u n i q u e S t r . r e p l a c e A l l ( ' / $ p r o f C a r d ' ,   ' ' ) ; 
 
     u n i q u e S t r   =   u n i q u e S t r . r e p l a c e A l l ( ' / ' ,   ' - ' ) ; 
 
 
 
     r e t u r n   u n i q u e S t r ; 
 
 } 
 
 
 
 / / /   G e n e r a t e   u n i q u e   I D   f o r   t h e   r e s o u r c e   U R L 
 
 / / /   I n   o r d e r   f o r   t h e   I D   t o   b e   u n i q u e   a c r o s s   a l l   w e b I D s   a n d   n o   o n e   c a n 
 
 / / /   r e v e r s e   e n g i n e e r   t h e   r e s o u r c e   b e i n g   s h a r e d   w e   a l s o   u s e   r e c e i v e r   w e b I d 
 
 / / /   i n   t h e   I D   g e n e r a t i o n   p r o c e s s 
 
 S t r i n g   g e t U n i q u e I d R e s U r l ( S t r i n g   r e s o u r c e U r l ,   S t r i n g   r e c e i v e r W e b I d )   { 
 
     r e t u r n   s h a 2 5 6 . c o n v e r t ( u t f 8 . e n c o d e ( r e s o u r c e U r l   +   r e c e i v e r W e b I d ) ) . t o S t r i n g ( ) ; 
 
 } 
 
 
 
 / / /   F r o m   a   g i v e n   r e s o u r c e   p a t h   [ r e s o u r c e P a t h ]   c r e a t e   i t s   U R L 
 
 / / /   [ i s C o n t a i n e r ]   s h o u l d   b e   t r u e   i f   t h e   r e s o u r c e   i s   a   d i r e c t o r y ,   o t h e r w i s e   f a l s e 
 
 / / /   r e t u r n s   t h e   f u l l   r e s o u r c e   U R L 
 
 
 
 F u t u r e < S t r i n g >   _ g e t R e s o u r c e U r l ( 
 
     S t r i n g   r e s o u r c e P a t h , 
 
     b o o l   i s C o n t a i n e r ,   [ 
 
     S t r i n g ?   e x t W e b I d , 
 
 ] )   a s y n c   { 
 
     / /   C h e c k   i f   r e s o u r c e   u r l   i s   n e e d e d   f o r   a n   e x t e r n a l   w e b I d 
 
     f i n a l   w e b I d   =   e x t W e b I d   ? ?   a w a i t   A u t h D a t a M a n a g e r . g e t W e b I d ( ) ; 
 
 
 
     / /   I f   w e b I d   i s   n u l l   ( u s e r   l o g g e d   o u t ) ,   r e t u r n   e m p t y   o r   t h r o w   i n f o r m a t i v e   e r r o r 
 
     i f   ( w e b I d   = =   n u l l   | |   w e b I d . i s E m p t y )   { 
 
         t h r o w   E x c e p t i o n ( ' U s e r   n o t   l o g g e d   i n :   c a n n o t   a c c e s s   r e s o u r c e   U R L ' ) ; 
 
     } 
 
 
 
     i f   ( ! w e b I d . c o n t a i n s ( p r o f C a r d ) )   { 
 
         t h r o w   E x c e p t i o n ( ' I n v a l i d   w e b I d   f o r m a t :   m u s t   c o n t a i n   $ p r o f C a r d ' ) ; 
 
     } 
 
 
 
     f i n a l   r e s o u r c e U r l   =   w e b I d . r e p l a c e A l l ( p r o f C a r d ,   r e s o u r c e P a t h ) ; 
 
 
 
     i f   ( i s C o n t a i n e r   & &   ! r e s o u r c e U r l . e n d s W i t h ( ' / ' ) )   { 
 
         r e t u r n   ' $ r e s o u r c e U r l / ' ; 
 
     } 
 
 
 
     r e t u r n   r e s o u r c e U r l ; 
 
 } 
 
 
 
 / / /   C r e a t e   t h e   U R L   f o r   a   f i l e 
 
 F u t u r e < S t r i n g >   g e t F i l e U r l ( S t r i n g   f i l e P a t h ,   [ S t r i n g ?   e x t W e b I d ] )   a s y n c   = > 
 
         a w a i t   _ g e t R e s o u r c e U r l ( f i l e P a t h ,   f a l s e ,   e x t W e b I d ) ; 
 
 
 
 / / /   C r e a t e   t h e   U R L   f o r   a   d i r e c t o r y   ( c o n t a i n e r ) 
 
 F u t u r e < S t r i n g >   g e t D i r U r l ( S t r i n g   d i r P a t h ,   [ S t r i n g ?   e x t W e b I d ] )   a s y n c   = > 
 
         a w a i t   _ g e t R e s o u r c e U r l ( d i r P a t h ,   t r u e ,   e x t W e b I d ) ; 
 
 
 
 / / /   G e t   r e s o u r c e   U r l   f r o m   a   f i l e n a m e ,   w i t h   d i f f e r e n t   o p t i o n s   f o r   h o w 
 
 / / /   t h e   f i l e n a m e   i s   p r o v i d e d .   I f   [ i s E x t e r n a l R e s ]   o r   [ i s F i l e U r l ]   i s 
 
 / / /   s e t   t o   t r u e ,   t h e   f i l e n a m e   i s   a l r e a d y   t h e   r e s o u r c e   u r l   a n d   i s 
 
 / / /   r e t u r n e d   u n c h a n g e d . 
 
 / / / 
 
 / / /   P a r a m e t e r s : 
 
 / / /   -   [ f i l e N a m e ]   -   n a m e   o f   f i l e   o f   i n t e r e s t . 
 
 / / /   -   [ i s F i l e ]   -   f l a g   d e s c r i b i n g   w h e t h e r   t h e   r e s o u r c e s   i s   a   f i l e   o r   n o t . 
 
 / / /   I f   f a l s e   t h e   [ f i l e N a m e ]   i s   a   d i r e c t o r y .   ( D e f a u l t :   t r u e ) . 
 
 / / /   -   [ i s F i l e P a t h ]   -   f l a g   d e s c r i b i n g   w h e t h e r   [ f i l e N a m e ]   i n c l u d e s   t h e 
 
 / / /   d i r e c t o r y   d a t a   p a t h .   ( D e f a u l t :   f a l s e ) . 
 
 / / /   -   [ i s F i l e U r l ]   -   f l a g   d e s c r i b i n g   w h e t h e r   [ f i l e N a m e ]   i s   t h e   u r l   o f   t h e 
 
 / / /   f i l e .   ( D e f a u l t :   f a l s e ) . 
 
 / / /   -   [ i s E x t e r n a l R e s ]   -   f l a g   d e s c r i b i n g   w h e t h e r   t h e   f i l e   i s   a n   e x t e r n a l 
 
 / / /   f i l e   s h a r e d   w i t h   t h e   u s e r .   I n   w h i c h   c a s e   t h e   [ f i l e N a m e ]   s h o u l d   b e 
 
 / / /   t h e   f u l l   U R L   o f   t h e   f i l e .   ( D e f a u l t :   f a l s e ) . 
 
 
 
 F u t u r e < S t r i n g >   f i l e n a m e T o R e s o u r c e U r l ( { 
 
     r e q u i r e d   S t r i n g   f i l e N a m e , 
 
     b o o l   i s F i l e   =   t r u e , 
 
     b o o l   i s F i l e U r l   =   f a l s e , 
 
     b o o l   i s E x t e r n a l R e s   =   f a l s e , 
 
 } )   a s y n c   { 
 
     f i n a l   S t r i n g   r e s o u r c e U r l ; 
 
     f i n a l   S t r i n g   f i l e P a t h ; 
 
 
 
     / /   N o t e :   e x t e r n a l   r e s o u r c e s   a l w a y s   s p e c i f i e d   b y   u r l 
 
     i f   ( i s E x t e r n a l R e s )   { 
 
         i s F i l e U r l   =   t r u e ; 
 
     } 
 
 
 
     / /   I f   n o t   a l r e a d y   a   u r l ,   g e t   u r l 
 
     i f   ( ! i s E x t e r n a l R e s   & &   ! i s F i l e U r l )   { 
 
         / /   G e t   t h e   f i l e   p a t h 
 
         / /   E n s u r e   p a t h   u s e s   c o r r e c t   p a t h   s e p a r a t o r s   a n d 
 
         / /   h a s   a p p   d a t a   d i r   p r e p e n d e d . 
 
         f i l e P a t h   =   a w a i t   n o r m a l i z e F i l e P a t h ( f i l e N a m e ,   n u l l ) ; 
 
 
 
         / /   G e t   t h e   u r l   o f   t h e   r e s o u r c e   b y   p r e p e n d i n g   t h e 
 
         / /   u s e r   =   o w n e r   w e b I D   ( e x c l u d i n g   p r o f C a r d ) 
 
         i f   ( i s F i l e )   { 
 
             r e s o u r c e U r l   =   a w a i t   g e t F i l e U r l ( f i l e P a t h ) ; 
 
         }   e l s e   { 
 
             r e s o u r c e U r l   =   a w a i t   g e t D i r U r l ( f i l e P a t h ) ; 
 
         } 
 
     }   e l s e   { 
 
         / /   U s e   f i l e N a m e ,   f i l e N a m e   a l r e a d y   t h e   r e s o u r c e   u r l 
 
         r e s o u r c e U r l   =   f i l e N a m e ; 
 
     } 
 
 
 
     r e t u r n   r e s o u r c e U r l ; 
 
 } 
 
 
 
 / / /   D e r i v e   e x t e r n a l   P O D   i n h e r i t e d   p a r e n t   d i r e c t o r y   u r l   f r o m   t h e   r e s o u r c e   u r l 
 
 / / /   a n d   p a r e n t   d i r e c t o r y   p a t h 
 
 S t r i n g   g e t E x t D i r U r l ( S t r i n g   r e s o u r c e U r l ,   S t r i n g   d i r P a t h )   { 
 
     i n t   p a t h I n d e x   =   r e s o u r c e U r l . i n d e x O f ( d i r P a t h ) ; 
 
 
 
     S t r i n g   d i r U r l   =   ' ' ; 
 
     i f   ( p a t h I n d e x   ! =   - 1 )   { 
 
         d i r U r l   =   r e s o u r c e U r l . s u b s t r i n g ( 0 ,   p a t h I n d e x   +   d i r P a t h . l e n g t h ) ; 
 
         i f   ( ! d i r U r l . e n d s W i t h ( ' / ' ) )   { 
 
             d i r U r l   + =   ' / ' ; 
 
         } 
 
     } 
 
 
 
     r e t u r n   d i r U r l ; 
 
 } 
 
 
 
 / / /   E n c r y p t   a   g i v e n   d a t a   s t r i n g   a n d   f o r m a t   t o   T T L 
 
 F u t u r e < S t r i n g >   g e t E n c T T L S t r ( 
 
     S t r i n g   f i l e P a t h , 
 
     S t r i n g   f i l e C o n t e n t , 
 
     K e y   k e y , 
 
     I V   i v ,   { 
 
     S t r i n g ?   e x t W e b I d , 
 
     S t r i n g ?   i n h e r i t K e y F r o m , 
 
 } )   a s y n c   { 
 
     f i n a l   t r i p l e s   =   { 
 
         U R I R e f ( a w a i t   g e t F i l e U r l ( f i l e P a t h ,   e x t W e b I d ) ) :   { 
 
             s o l i d T e r m s N S . n s . w i t h A t t r ( p a t h P r e d ) :   f i l e P a t h , 
 
             s o l i d T e r m s N S . n s . w i t h A t t r ( i v P r e d ) :   i v . b a s e 6 4 , 
 
             i f   ( i n h e r i t K e y F r o m   ! =   n u l l ) 
 
                 s o l i d T e r m s N S . n s . w i t h A t t r ( i n h e r i t K e y P r e d ) :   i n h e r i t K e y F r o m , 
 
             s o l i d T e r m s N S . n s . w i t h A t t r ( e n c D a t a P r e d ) :   e n c r y p t D a t a ( f i l e C o n t e n t ,   k e y ,   i v ) , 
 
         } , 
 
     } ; 
 
 
 
     f i n a l   b i n d N S   =   { s o l i d T e r m s N S . p r e f i x :   s o l i d T e r m s N S . n s } ; 
 
 
 
     r e t u r n   t r i p l e M a p T o T u r t l e ( t r i p l e s ,   b i n d N a m e s p a c e s :   b i n d N S ) ; 
 
 } 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   f i l e   w i t h   v e r i f i c a t i o n   k e y   a n d   p r i v a t e   k e y 
 
 F u t u r e < S t r i n g >   g e t E n c K e y P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   e n c D i r ,   e n c K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   f i l e   w i t h   i n d i v i d u a l   k e y s 
 
 F u t u r e < S t r i n g >   g e t I n d K e y P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   e n c D i r ,   i n d K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   f i l e   w i t h   p u b l i c   k e y s 
 
 F u t u r e < S t r i n g >   g e t P u b K e y P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   s h a r i n g D i r ,   p u b K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   p u b l i c   f i l e   w i t h   i n d i v i d u a l   k e y s 
 
 F u t u r e < S t r i n g >   g e t P u b I n d K e y P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   s h a r i n g D i r ,   p u b I n d K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   f i l e   w i t h   i n d i v i d u a l   k e y s   a c c e s s e d   o n l y 
 
 / / /   b y   a u t h e n t i c a t e d   u s e r s 
 
 F u t u r e < S t r i n g >   g e t A u t h U s e r I n d K e y P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   s h a r i n g D i r ,   a u t h U s e r I n d K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   t h e   d a t a   d i r e c t o r y 
 
 F u t u r e < S t r i n g >   g e t D a t a D i r P a t h ( )   a s y n c   = >   [ a p p D i r N a m e ,   d a t a D i r ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   t h e   s h a r e d   d i r e c t o r y 
 
 F u t u r e < S t r i n g >   g e t S h a r e d D i r P a t h ( )   a s y n c   = >   [ a p p D i r N a m e ,   s h a r e d D i r ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   t h e   f i l e   w i t h   s h a r e d   i n d i v i d u a l   k e y s 
 
 F u t u r e < S t r i n g >   g e t S h a r e d K e y F i l e P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   s h a r e d D i r ,   s h a r e d K e y F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   t h e   e n c r y p t i o n   d i r e c t o r y 
 
 F u t u r e < S t r i n g >   g e t E n c D i r P a t h ( )   a s y n c   = >   [ a p p D i r N a m e ,   e n c D i r ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   R e t u r n s   t h e   p a t h   o f   t h e   e n c r y p t i o n   d i r e c t o r y 
 
 F u t u r e < S t r i n g >   g e t P e r m L o g F i l e P a t h ( )   a s y n c   = > 
 
         [ a p p D i r N a m e ,   l o g s D i r ,   p e r m L o g F i l e ] . j o i n ( ' / ' ) ; 
 
 
 
 / / /   E x t r a c t   t h e   a p p   n a m e   a n d   t h e   v e r s i o n   f r o m   t h e   p a c k a g e   i n f o 
 
 / / /   R e t u r n   a   r e c o r d   ( w i t h   n a m e d   f i e l d s   h t t p s : / / d a r t . d e v / l a n g u a g e / r e c o r d s ) 
 
 
 
 F u t u r e < ( { S t r i n g   n a m e ,   S t r i n g   v e r s i o n } ) >   g e t A p p N a m e V e r s i o n ( )   a s y n c   = > 
 
         ( n a m e :   a w a i t   A p p I n f o . n a m e ,   v e r s i o n :   a w a i t   A p p I n f o . v e r s i o n ) ; 
 
 
 
 / / /   R e t u r n   t h e   w e b   I D 
 
 F u t u r e < S t r i n g ? >   g e t W e b I d ( )   a s y n c   = >   A u t h D a t a M a n a g e r . g e t W e b I d ( ) ; 
 
 
 
 / / /   C h e c k   w h e t h e r   a   u s e r   i s   l o g g e d   i n   o r   n o t 
 
 / / / 
 
 / / /   C h e c k   i f   t h e   l o c a l   s t o r a g e   h a s   a u t h e n t i c a t i o n 
 
 / / /   d e t a i l s   o f   t h e   u s e r   a n d   a l s o   c h e c k   w h e t h e r   t h e 
 
 / / /   a c c e s s   t o k e n   i s   e x p i r e d   o r   n o t 
 
 / / /   r e t u r n s   b o o l e a n 
 
 
 
 F u t u r e < b o o l >   c h e c k L o g g e d I n ( )   a s y n c   { 
 
     f i n a l   w e b I d   =   a w a i t   A u t h D a t a M a n a g e r . g e t W e b I d ( ) ; 
 
 
 
     i f   ( w e b I d   ! =   n u l l   & &   w e b I d . i s N o t E m p t y )   { 
 
         f i n a l   a c c e s s T o k e n   =   a w a i t   A u t h D a t a M a n a g e r . g e t A c c e s s T o k e n ( ) ; 
 
         i f   ( a c c e s s T o k e n   ! =   n u l l   & &   ! J w t D e c o d e r . i s E x p i r e d ( a c c e s s T o k e n ) )   { 
 
             r e t u r n   t r u e ; 
 
         } 
 
     } 
 
 
 
     r e t u r n   f a l s e ; 
 
 } 
 
 
 
 / / /   C r e a t e   a   d i r e c t o r y   w i t h   t h e   g i v e n   U R L 
 
 
 
 F u t u r e < v o i d >   c r e a t e D i r ( S t r i n g   d i r U r l )   a s y n c   { 
 
     i f   ( ! d i r U r l . e n d s W i t h ( ' / ' ) )   { 
 
         t h r o w   E x c e p t i o n ( ' D i r e c t o r y   U R L   m u s t   e n d   w i t h   / :   $ d i r U r l ' ) ; 
 
     } 
 
     a w a i t   c r e a t e R e s o u r c e ( 
 
         d i r U r l , 
 
         i s F i l e :   f a l s e , 
 
         r e p l a c e I f E x i s t :   f a l s e , 
 
         c o n t e n t T y p e :   R e s o u r c e C o n t e n t T y p e . d i r e c t o r y , 
 
     ) ; 
 
 } 
 
 
 
 / / /   D e l e t e   l o g i n   i n f o r m a t i o n   f r o m   t h e   l o c a l   s t o r a g e 
 
 / / / 
 
 / / /   r e t u r n s   t r u e   i f   s u c c e s s f u l 
 
 
 
 F u t u r e < b o o l >   d e l e t e L o g I n ( )   a s y n c   = >   A u t h D a t a M a n a g e r . r e m o v e A u t h D a t a ( ) ; 
 
 
 
 / / /   G e n e r a t e s   a   l i s t   o f   d e f a u l t   f o l d e r   p a t h s   f o r   a   g i v e n   a p p l i c a t i o n . 
 
 / / / 
 
 / / /   T h i s   f u n c t i o n   t a k e s   t h e   n a m e   o f   a n   a p p l i c a t i o n   a s   i n p u t   a n d   r e t u r n s   a   l i s t   o f   s t r i n g s . 
 
 / / /   E a c h   s t r i n g   i n   t h e   l i s t   r e p r e s e n t s   a   p a t h   t o   a   d e f a u l t   f o l d e r   f o r   t h e   a p p l i c a t i o n . 
 
 
 
 F u t u r e < L i s t < S t r i n g > >   g e n e r a t e D e f a u l t F o l d e r s ( )   a s y n c   { 
 
     f i n a l   d a t a D i r L o c   =   [ a p p D i r N a m e ,   d a t a D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   s h a r i n g D i r L o c   =   [ a p p D i r N a m e ,   s h a r i n g D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   s h a r e d D i r L o c   =   [ a p p D i r N a m e ,   s h a r e d D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   e n c D i r L o c   =   [ a p p D i r N a m e ,   e n c D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   l o g D i r L o c   =   [ a p p D i r N a m e ,   l o g s D i r ] . j o i n ( ' / ' ) ; 
 
 
 
     f i n a l   f o l d e r s   =   [ 
 
         a p p D i r N a m e , 
 
         s h a r i n g D i r L o c , 
 
         s h a r e d D i r L o c , 
 
         d a t a D i r L o c , 
 
         e n c D i r L o c , 
 
         l o g D i r L o c , 
 
     ] ; 
 
     r e t u r n   f o l d e r s ; 
 
 } 
 
 
 
 / / /   G e n e r a t e s   a   l i s t   o f   d e f a u l t   f o l d e r   p a t h s   f o r   a   g i v e n   a p p l i c a t i o n . 
 
 / / / 
 
 / / /   T h i s   f u n c t i o n   t a k e s   t h e   n a m e   o f   a n   a p p l i c a t i o n   a s   i n p u t   a n d   r e t u r n s   a   l i s t   o f   s t r i n g s . 
 
 / / /   E a c h   s t r i n g   i n   t h e   l i s t   r e p r e s e n t s   a   p a t h   t o   a   d e f a u l t   f o l d e r   f o r   t h e   a p p l i c a t i o n . 
 
 
 
 F u t u r e < M a p < d y n a m i c ,   d y n a m i c > >   g e n e r a t e D e f a u l t F i l e s ( )   a s y n c   { 
 
     f i n a l   s h a r i n g D i r L o c   =   [ a p p D i r N a m e ,   s h a r i n g D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   s h a r e d D i r L o c   =   [ a p p D i r N a m e ,   s h a r e d D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   e n c D i r L o c   =   [ a p p D i r N a m e ,   e n c D i r ] . j o i n ( ' / ' ) ; 
 
     f i n a l   l o g D i r L o c   =   [ a p p D i r N a m e ,   l o g s D i r ] . j o i n ( ' / ' ) ; 
 
 
 
     f i n a l   f i l e s   =   { 
 
         s h a r i n g D i r L o c :   [ 
 
             p u b K e y F i l e , 
 
             ' $ p u b K e y F i l e . a c l ' , 
 
         ] , 
 
         l o g D i r L o c :   [ 
 
             p e r m L o g F i l e , 
 
             ' $ p e r m L o g F i l e . a c l ' , 
 
         ] , 
 
         s h a r e d D i r L o c :   [ ' . a c l ' ] , 
 
         e n c D i r L o c :   [ e n c K e y F i l e ,   i n d K e y F i l e ] , 
 
     } ; 
 
     r e t u r n   f i l e s ; 
 
 } 
 
 
 
 / / /   S e t   d i r e c t o r y   n a m e   f o r   t h e   a p p   f o r   s t o r i n g   t h e   P O D   d a t a 
 
 / / / 
 
 / / /   I f   n o t   i n i t i a l l y   s e t   t h e   a p p   n a m e   w i l l   b e   t a k e n   b y   d e f a u l t . 
 
 
 
 F u t u r e < v o i d >   s e t A p p D i r N a m e ( S t r i n g   i n p u t A p p D i r N a m e )   a s y n c   { 
 
     i f   ( i n p u t A p p D i r N a m e . i s E m p t y )   { 
 
         a p p D i r N a m e   =   a w a i t   A p p I n f o . c a n o n i c a l N a m e ; 
 
     }   e l s e   { 
 
         a p p D i r N a m e   =   i n p u t A p p D i r N a m e ; 
 
     } 
 
 } 
 
 
 
 / / /   G e t   r e s o u r c e   a c l   f i l e   p a t h 
 
 S t r i n g   g e t R e s A c l F i l e ( S t r i n g   r e s o u r c e U r l ,   [ b o o l   i s F i l e   =   t r u e ] )   { 
 
     f i n a l   r e s o u r c e A c l U r l   =   r e s o u r c e U r l . e n d s W i t h ( ' . a c l ' ) 
 
             ?   r e s o u r c e U r l 
 
             :   i s F i l e 
 
                     ?   ' $ r e s o u r c e U r l . a c l ' 
 
                     :   ' $ r e s o u r c e U r l / . a c l ' ; 
 
 
 
     r e t u r n   r e s o u r c e A c l U r l ; 
 
 } 
 
 
 
 / / /   E x t r a c t   p e r m i s s i o n   d e t a i l s   o f   a   f i l e   i n t o   a   m a p . 
 
 / / /   R e t u r n s   a   m a p   w h e r e   k e y s   a r e   p e r m i s s i o n   r e c e i v e r   w e b I d s   a n d 
 
 / / /   v a l u e s   a r e   t h e   l i s t   o f   p e r m i s s i o n s 
 
 M a p < d y n a m i c ,   d y n a m i c >   e x t r a c t A c l P e r m ( M a p < d y n a m i c ,   d y n a m i c >   a c l F i l e C o n t e n t M a p )   { 
 
     f i n a l   f i l e P e r m M a p   =   < d y n a m i c ,   d y n a m i c > { } ; 
 
     f o r   ( f i n a l   a c c e s s S t r   i n   a c l F i l e C o n t e n t M a p . k e y s )   { 
 
         f i n a l   p e r m L i s t   =   a c l F i l e C o n t e n t M a p [ a c c e s s S t r ] [ m o d e P r e d ] ; 
 
         f i n a l   r e c e i v e r M a p   =   { } ; 
 
 
 
         i f   ( ( a c l F i l e C o n t e n t M a p [ a c c e s s S t r ]   a s   M a p ) . c o n t a i n s K e y ( a g e n t P r e d ) )   { 
 
             f o r   ( f i n a l   r e c e i v e r I d 
 
                     i n   a c l F i l e C o n t e n t M a p [ a c c e s s S t r ] [ a g e n t P r e d ]   a s   L i s t )   { 
 
                 r e c e i v e r M a p [ r e c e i v e r I d ]   =   a g e n t P r e d ; 
 
             } 
 
         } 
 
         i f   ( ( a c l F i l e C o n t e n t M a p [ a c c e s s S t r ]   a s   M a p ) . c o n t a i n s K e y ( a g e n t C l a s s P r e d ) )   { 
 
             f o r   ( f i n a l   r e c e i v e r I d 
 
                     i n   a c l F i l e C o n t e n t M a p [ a c c e s s S t r ] [ a g e n t C l a s s P r e d ]   a s   L i s t )   { 
 
                 r e c e i v e r M a p [ r e c e i v e r I d ]   =   a g e n t C l a s s P r e d ; 
 
             } 
 
         } 
 
         i f   ( ( a c l F i l e C o n t e n t M a p [ a c c e s s S t r ]   a s   M a p ) . c o n t a i n s K e y ( a g e n t G r o u p P r e d ) )   { 
 
             f o r   ( f i n a l   r e c e i v e r I d 
 
                     i n   a c l F i l e C o n t e n t M a p [ a c c e s s S t r ] [ a g e n t G r o u p P r e d ]   a s   L i s t )   { 
 
                 r e c e i v e r M a p [ r e c e i v e r I d ]   =   a g e n t G r o u p P r e d ; 
 
             } 
 
         } 
 
 
 
         f o r   ( f i n a l   r e c e i v e r I d   i n   r e c e i v e r M a p . k e y s )   { 
 
             i f   ( f i l e P e r m M a p . c o n t a i n s K e y ( r e c e i v e r I d ) )   { 
 
                 f i l e P e r m M a p [ r e c e i v e r I d ] [ p e r m S t r ]   + =   p e r m L i s t ; 
 
                 f i l e P e r m M a p [ r e c e i v e r I d ] [ a g e n t S t r ]   =   r e c e i v e r M a p [ r e c e i v e r I d ] ; 
 
             }   e l s e   { 
 
                 f i l e P e r m M a p [ r e c e i v e r I d ]   =   { 
 
                     p e r m S t r :   p e r m L i s t , 
 
                     a g e n t S t r :   r e c e i v e r M a p [ r e c e i v e r I d ] , 
 
                 } ; 
 
             } 
 
         } 
 
     } 
 
 
 
     r e t u r n   f i l e P e r m M a p ; 
 
 } 
 
 
 
 / / /   G e t   r e s o u r c e   n a m e   f r o m   U R L 
 
 S t r i n g   g e t R e s N a m e F r o m U r l ( S t r i n g   r e s o u r c e U r l )   { 
 
     r e t u r n   r e s o u r c e U r l . s p l i t ( ' / ' ) . l a s t ; 
 
 } 
 
 
 
 / / /   G e t   t o k e n s   n e c e s s a r y   t o   f e t c h   a   r e s o u r c e   f r o m   a   P O D 
 
 / / / 
 
 / / /   r e t u r n s   t h e   a c c e s s   t o k e n   a n d   D P o P   t o k e n 
 
 F u t u r e < ( { S t r i n g   a c c e s s T o k e n ,   S t r i n g   d P o p T o k e n } ) >   g e t T o k e n s F o r R e s o u r c e ( 
 
     S t r i n g   r e s o u r c e U r l , 
 
     S t r i n g   h t t p M e t h o d , 
 
 )   a s y n c   { 
 
     f i n a l   a u t h D a t a   =   a w a i t   A u t h D a t a M a n a g e r . l o a d A u t h D a t a ( ) ; 
 
     i f   ( a u t h D a t a   = =   n u l l )   { 
 
         t h r o w   E x c e p t i o n ( ' N o   a u t h e n t i c a t i o n   d a t a   a v a i l a b l e ' ) ; 
 
     } 
 
 
 
     f i n a l   r s a I n f o   =   a u t h D a t a [ ' r s a I n f o ' ] ; 
 
     f i n a l   r s a K e y P a i r   =   r s a I n f o [ ' r s a ' ]   a s   K e y P a i r ; 
 
     f i n a l   p u b l i c K e y J w k   =   r s a I n f o [ ' p u b K e y J w k ' ] ; 
 
 
 
     r e t u r n   ( 
 
         a c c e s s T o k e n :   a u t h D a t a [ ' a c c e s s T o k e n ' ]   a s   S t r i n g , 
 
         d P o p T o k e n :   g e n D p o p T o k e n ( r e s o u r c e U r l ,   r s a K e y P a i r ,   p u b l i c K e y J w k ,   h t t p M e t h o d ) , 
 
     ) ; 
 
 } 
 
 
 
 / / /   L o g g i n g   o u t   t h e   u s e r   w i t h   c o m p r e h e n s i v e   e r r o r   h a n d l i n g   a n d   p l a t f o r m   s u p p o r t 
 
 / / / 
 
 / / /   T h i s   f u n c t i o n   p e r f o r m s   a   c o m p l e t e   l o g o u t   t h a t   i n c l u d e s : 
 
 / / /   1 .   C l e a r i n g   a l l   e n c r y p t i o n   k e y s   f r o m   m e m o r y 
 
 / / /   2 .   R e m o v i n g   a u t h e n t i c a t i o n   d a t a   f r o m   s e c u r e   s t o r a g e 
 
 / / /   3 .   C a l l i n g   t h e   O A u t h 2   l o g o u t   e n d p o i n t   ( w i t h   e r r o r   t o l e r a n c e   o n   w e b ) 
 
 / / / 
 
 / / /   R e t u r n s   t r u e   i f   l o g o u t   s u c c e e d s   o r   c r i t i c a l   o p e r a t i o n s   c o m p l e t e , 
 
 / / /   f a l s e   o n l y   i f   c r i t i c a l   o p e r a t i o n s   ( k e y / a u t h   c l e a n u p )   f a i l . 
 
 F u t u r e < b o o l >   l o g o u t P o d ( )   a s y n c   { 
 
     t r y   { 
 
         / /   S t e p   1 :   C l e a r   a l l   c a c h e d   e n c r y p t i o n   k e y s   a n d   s e c u r i t y   d a t a   f r o m   m e m o r y 
 
         / /   T h i s   i s   C R I T I C A L   a n d   m u s t   b e   d o n e   r e g a r d l e s s   o f   o t h e r   f a i l u r e s 
 
         a w a i t   K e y M a n a g e r . c l e a r ( ) ; 
 
         d e b u g P r i n t ( ' l o g o u t P o d ( )   = >   K e y M a n a g e r . c l e a r ( )   c o m p l e t e d ' ) ; 
 
 
 
         / /   S t e p   2 :   R e m o v e   a u t h e n t i c a t i o n   d a t a   f r o m   s e c u r e   s t o r a g e 
 
         / /   T h i s   i s   C R I T I C A L   -   m u s t   s u c c e e d 
 
         f i n a l   a u t h D a t a R e m o v e d   =   a w a i t   A u t h D a t a M a n a g e r . r e m o v e A u t h D a t a ( ) ; 
 
         i f   ( ! a u t h D a t a R e m o v e d )   { 
 
             d e b u g P r i n t ( 
 
                 ' l o g o u t P o d ( )   = >   W A R N I N G :   A u t h D a t a M a n a g e r . r e m o v e A u t h D a t a ( )   f a i l e d ' , 
 
             ) ; 
 
             / /   D o n ' t   r e t u r n   f a l s e   y e t   -   l o g o u t   e n d p o i n t   i s   s t i l l   n e e d e d 
 
         } 
 
 
 
         / /   S t e p   2 . 5 :   C l e a r   a p p l i c a t i o n - s p e c i f i c   c a c h e s   B E F O R E   n e t w o r k   c a l l 
 
         / /   T h i s   i s   C R I T I C A L   t o   p r e v e n t   r a c e   c o n d i t i o n s   w h e r e   U I   r e a d s   s t a l e   c a c h e 
 
         / /   d u r i n g   l o g o u t ,   e s p e c i a l l y   w h e n   n e t w o r k   i s   s l o w 
 
         i f   ( _ o n L o g o u t C l e a r C a c h e s   ! =   n u l l )   { 
 
             t r y   { 
 
                 a w a i t   _ o n L o g o u t C l e a r C a c h e s ! ( ) ; 
 
             }   o n   O b j e c t   c a t c h   ( e )   { 
 
                 d e b u g P r i n t ( 
 
                     ' l o g o u t P o d ( )   = >   W A R N I N G :   A p p l i c a t i o n   c a c h e   c a l l b a c k   f a i l e d   ( n o n - c r i t i c a l ) :   $ e ' , 
 
                 ) ; 
 
                 / /   C o n t i n u e   -   t h e   c r i t i c a l   a u t h   d a t a   i s   a l r e a d y   c l e a r e d 
 
             } 
 
         }   e l s e   { 
 
             d e b u g P r i n t ( 
 
                 ' l o g o u t P o d ( )   = >   N o   a p p l i c a t i o n   c a c h e   c a l l b a c k   r e g i s t e r e d ' , 
 
             ) ; 
 
         } 
 
 
 
         / /   S t e p   3 :   G e t   t h e   l o g o u t   U R L   a n d   a t t e m p t   O A u t h 2   l o g o u t 
 
         / /   T h i s   i s   O P T I O N A L   -   s h o u l d   n o t   b l o c k   i f   i t   f a i l s 
 
         f i n a l   l o g o u t U r l   =   a w a i t   A u t h D a t a M a n a g e r . g e t L o g o u t U r l ( ) ; 
 
         i f   ( l o g o u t U r l   ! =   n u l l   & &   l o g o u t U r l . i s N o t E m p t y )   { 
 
             t r y   { 
 
                 / /   C a l l   t h e   O A u t h 2   l o g o u t   e n d p o i n t 
 
                 / /   O n   w e b ,   t h i s   m a y   f a i l   w i t h   p l a t f o r m - r e l a t e d   e x c e p t i o n s ,   b u t   w e   c o n t i n u e   a n y w a y 
 
                 a w a i t   l o g o u t ( l o g o u t U r l ) ; 
 
                 d e b u g P r i n t ( ' l o g o u t P o d ( )   = >   O A u t h 2   l o g o u t   e n d p o i n t   c a l l e d   s u c c e s s f u l l y ' ) ; 
 
             }   o n   O b j e c t   c a t c h   ( e )   { 
 
                 / /   O n   F l u t t e r   W e b ,   p l a t f o r m - r e l a t e d   e x c e p t i o n s   m i g h t   o c c u r 
 
                 / /   T h i s   i s   N O T   a   c r i t i c a l   f a i l u r e   -   t h e   l o c a l   s e s s i o n   i s   a l r e a d y   c l e a r e d 
 
                 d e b u g P r i n t ( ' l o g o u t P o d ( )   = >   O A u t h 2   l o g o u t   w a r n i n g   ( n o n - c r i t i c a l ) :   $ e ' ) ; 
 
                 / /   C o n t i n u e   -   l o c a l   d a t a   i s   a l r e a d y   c l e a r e d   w h i c h   i s   m o s t   i m p o r t a n t 
 
             } 
 
         }   e l s e   { 
 
             d e b u g P r i n t ( 
 
                 ' l o g o u t P o d ( )   = >   N o   l o g o u t   U R L   a v a i l a b l e ,   s k i p p i n g   O A u t h 2   l o g o u t ' , 
 
             ) ; 
 
         } 
 
 
 
         / /   S u c c e s s   i f   w e   c l e a r e d   t h e   l o c a l   d a t a   ( m o s t   i m p o r t a n t   p a r t ) 
 
         r e t u r n   a u t h D a t a R e m o v e d ; 
 
     }   o n   O b j e c t   c a t c h   ( e )   { 
 
         / /   C a t c h   a n y   r e m a i n i n g   e x c e p t i o n s 
 
         d e b u g P r i n t ( ' l o g o u t P o d ( )   = >   C R I T I C A L   E R R O R :   $ e ' ) ; 
 
         / /   E v e n   i f   w e   r e a c h   h e r e ,   a t t e m p t   t o   c l e a r   a u t h   d a t a   a s   f a l l b a c k 
 
         t r y   { 
 
             a w a i t   A u t h D a t a M a n a g e r . r e m o v e A u t h D a t a ( ) ; 
 
             a w a i t   K e y M a n a g e r . c l e a r ( ) ; 
 
         }   c a t c h   ( f a l l b a c k E r r o r )   { 
 
             d e b u g P r i n t ( ' l o g o u t P o d ( )   = >   F a l l b a c k   c l e a n u p   a l s o   f a i l e d :   $ f a l l b a c k E r r o r ' ) ; 
 
         } 
 
         r e t u r n   f a l s e ; 
 
     } 
 
 } 
 
 
 
 / / /   R e m o v e s   h e a d e r   a n d   f o o t e r   ( w h i c h   m e s s   u p   t h e   T T L   f o r m a t )   f r o m   a   P E M - f o r m a t t e d   p u b l i c   k e y   s t r i n g . 
 
 / / / 
 
 / / /   T h i s   f u n c t i o n   t a k e s   a   p u b l i c   k e y   s t r i n g ,   t y p i c a l l y   i n   P E M   f o r m a t ,   a n d   r e m o v e s 
 
 / / /   t h e   s t a n d a r d   P E M   h e a d e r s   a n d   f o o t e r s . 
 
 
 
 S t r i n g   t r i m P u b K e y S t r ( S t r i n g   k e y S t r )   { 
 
     f i n a l   i t e m L i s t   =   k e y S t r . s p l i t ( ' \ n ' ) ; 
 
     i t e m L i s t . r e m o v e ( ' - - - - - B E G I N   R S A   P U B L I C   K E Y - - - - - ' ) ; 
 
     i t e m L i s t . r e m o v e ( ' - - - - - E N D   R S A   P U B L I C   K E Y - - - - - ' ) ; 
 
     i t e m L i s t . r e m o v e ( ' - - - - - B E G I N   P U B L I C   K E Y - - - - - ' ) ; 
 
     i t e m L i s t . r e m o v e ( ' - - - - - E N D   P U B L I C   K E Y - - - - - ' ) ; 
 
 
 
     f i n a l   k e y S t r T r i m m e d   =   i t e m L i s t . j o i n ( ) ; 
 
 
 
     r e t u r n   k e y S t r T r i m m e d ; 
 
 } 
 
 
 
 / / /   I n i t i a l i s e   t h e   d i r e c t o r y   a n d   f i l e   s t r u c t u r e   i n   a   P O D 
 
 
 
 F u t u r e < v o i d >   i n i t P o d ( 
 
     S t r i n g   s e c u r i t y K e y ,   { 
 
     L i s t < S t r i n g > ?   d i r U r l s , 
 
     L i s t < S t r i n g > ?   f i l e U r l s , 
 
 } )   a s y n c   { 
 
     / /   C h e c k   i f   t h e   u s e r   h a s   l o g g e d   i n 
 
 
 
     f i n a l   l o g g e d I n   =   a w a i t   c h e c k L o g g e d I n ( ) ; 
 
     i f   ( ! l o g g e d I n )   { 
 
         t h r o w   N o t L o g g e d I n E x c e p t i o n ( ' C a n   n o t   i n i t i a l i s e   P O D   w i t h o u t   l o g g i n g   i n ' ) ; 
 
     } 
 
 
 
     / /   C h e c k   ( a n d   g e n e r a t e )   t h e   d i r e c t o r y   U R L s 
 
 
 
     i f   ( d i r U r l s   = =   n u l l   | |   d i r U r l s . i s E m p t y )   { 
 
         f i n a l   d e f a u l t D i r s   =   a w a i t   g e n e r a t e D e f a u l t F o l d e r s ( ) ; 
 
         d i r U r l s   =   [ f o r   ( f i n a l   d   i n   d e f a u l t D i r s )   a w a i t   g e t D i r U r l ( d ) ] ; 
 
     } 
 
 
 
     / /   R e q u i r e   t h e   c r e a t i o n   o f   t h e   e n c r y p t i o n   d i r e c t o r y   a n d 
 
     / /   t h e   e n c K e y F i l e   a n d   i n d K e y F i l e   i n   i t . 
 
     / /   ( T h e   a p p   a s k s   f o r   t h e   s e c u r i t y   k e y ,   s o   t h i s   i s   a   r e a s o n a b l e   r e q u i r e m e n t ? ) 
 
 
 
     f i n a l   e n c D i r U r l   =   a w a i t   g e t D i r U r l ( a w a i t   g e t E n c D i r P a t h ( ) ) ; 
 
     i f   ( ! d i r U r l s . c o n t a i n s ( e n c D i r U r l ) )   { 
 
         t h r o w   E x c e p t i o n ( ' C a n   n o t   i n i t i a l i s e   P O D   w i t h o u t   c r e a t i n g   $ e n c D i r U r l ' ) ; 
 
     } 
 
 
 
     / /   C r e a t e   t h e   r e q u i r e d   d i r e c t o r i e s 
 
 
 
     f o r   ( f i n a l   d   i n   d i r U r l s )   { 
 
         a w a i t   c r e a t e R e s o u r c e ( 
 
             d , 
 
             i s F i l e :   f a l s e , 
 
             c o n t e n t T y p e :   R e s o u r c e C o n t e n t T y p e . d i r e c t o r y , 
 
         ) ; 
 
     } 
 
 
 
     / /   C h e c k   ( a n d   g e n e r a t e )   t h e   f i l e   U R L s 
 
 
 
     i f   ( f i l e U r l s   = =   n u l l   | |   f i l e U r l s . i s E m p t y )   { 
 
         f i n a l   d e f a u l t F i l e s   =   a w a i t   g e n e r a t e D e f a u l t F i l e s ( ) ; 
 
         f i l e U r l s   =   < S t r i n g > [ ] ; 
 
         f o r   ( f i n a l   e n t r y   i n   d e f a u l t F i l e s . e n t r i e s )   { 
 
             f i n a l   d   =   e n t r y . k e y ; 
 
             f o r   ( f i n a l   f   i n   e n t r y . v a l u e   a s   L i s t )   { 
 
                 f i l e U r l s . a d d ( [ d ,   f ] . j o i n ( ' / ' ) ) ; 
 
             } 
 
         } 
 
     } 
 
 
 
     / /   C r e a t e   t h e   e n c K e y F i l e ,   i n d K e y F i l e   a n d   p u b K e y F i l e 
 
     / /   a n d   r e m o v e   t h e m   f r o m   t h e   f i l e U r l s   l i s t 
 
 
 
     a w a i t   K e y M a n a g e r . i n i t P o d K e y s ( s e c u r i t y K e y ) ; 
 
     f i l e U r l s . r e m o v e ( a w a i t   g e t F i l e U r l ( a w a i t   g e t E n c K e y P a t h ( ) ) ) ; 
 
     f i l e U r l s . r e m o v e ( a w a i t   g e t F i l e U r l ( a w a i t   g e t I n d K e y P a t h ( ) ) ) ; 
 
     f i l e U r l s . r e m o v e ( a w a i t   g e t F i l e U r l ( a w a i t   g e t P u b K e y P a t h ( ) ) ) ; 
 
 
 
     f o r   ( f i n a l   f   i n   f i l e U r l s )   { 
 
         f i n a l   f i l e N a m e   =   f . s p l i t ( ' / ' ) . l a s t ; 
 
         l a t e   S t r i n g   f i l e C o n t e n t ; 
 
         l a t e   b o o l   a c l F l a g ; 
 
 
 
         i f   ( f . s p l i t ( ' . ' ) . l a s t   = =   ' a c l ' )   { 
 
             f i n a l   i t e m s   =   f . s p l i t ( ' . ' ) ; 
 
             f i n a l   r e s o u r c e U r l   =   i t e m s . g e t R a n g e ( 0 ,   i t e m s . l e n g t h   -   1 ) . j o i n ( ' . ' ) ; 
 
             l a t e   S e t < A c c e s s M o d e >   p u b l i c A c c e s s ; 
 
             v a r   i s F i l e   =   t r u e ; 
 
             s w i t c h   ( f i l e N a m e )   { 
 
                 c a s e   ' $ p u b K e y F i l e . a c l ' : 
 
                     p u b l i c A c c e s s   =   { A c c e s s M o d e . r e a d } ; 
 
                 c a s e   ' $ p e r m L o g F i l e . a c l ' : 
 
                     p u b l i c A c c e s s   =   { A c c e s s M o d e . a p p e n d } ; 
 
                 d e f a u l t : 
 
                     d e b u g P r i n t ( f i l e N a m e ) ; 
 
                     i f   ( f i l e N a m e   ! =   ' . a c l ' )   { 
 
                         d e b u g P r i n t ( ' W a r n i n g :   U n e x p e c t e d   A C L   f i l e :   $ f i l e N a m e ' ) ; 
 
                     } 
 
                     p u b l i c A c c e s s   =   { A c c e s s M o d e . r e a d ,   A c c e s s M o d e . w r i t e } ; 
 
                     i s F i l e   =   f a l s e ; 
 
             } 
 
 
 
             f i l e C o n t e n t   =   a w a i t   g e n A c l T u r t l e ( 
 
                 r e s o u r c e U r l , 
 
                 i s F i l e :   i s F i l e , 
 
                 p u b l i c A c c e s s :   p u b l i c A c c e s s , 
 
             ) ; 
 
 
 
             a c l F l a g   =   t r u e ; 
 
         }   e l s e   { 
 
             d e b u g P r i n t ( f i l e N a m e ) ; 
 
             i f   ( f i l e N a m e   ! =   p e r m L o g F i l e )   { 
 
                 d e b u g P r i n t ( ' W a r n i n g :   U n e x p e c t e d   f i l e :   $ f i l e N a m e ' ) ; 
 
             } 
 
             f i l e C o n t e n t   =   g e n P e r m L o g T T L S t r ( f ) ; 
 
             a c l F l a g   =   f a l s e ; 
 
         } 
 
 
 
         a w a i t   c r e a t e R e s o u r c e ( f ,   c o n t e n t :   f i l e C o n t e n t ,   r e p l a c e I f E x i s t :   a c l F l a g ) ; 
 
     } 
 
 } 
 
 
 
 / / /   D e l e t e   t h e   A C L   f i l e   f o r   a   r e s o u r c e 
 
 F u t u r e < v o i d >   d e l e t e A c l F o r R e s o u r c e ( S t r i n g   r e s o u r c e U r l )   a s y n c   { 
 
     f i n a l   a c l U r l   =   ' $ r e s o u r c e U r l . a c l ' ; 
 
     f i n a l   s t a t u s   =   a w a i t   c h e c k R e s o u r c e S t a t u s ( a c l U r l ) ; 
 
 
 
     s w i t c h   ( s t a t u s )   { 
 
         c a s e   R e s o u r c e S t a t u s . e x i s t : 
 
             a w a i t   d e l e t e R e s o u r c e ( a c l U r l ,   R e s o u r c e C o n t e n t T y p e . t u r t l e T e x t ) ; 
 
 
 
         c a s e   R e s o u r c e S t a t u s . f o r b i d d e n : 
 
             d e b u g P r i n t ( 
 
                 ' A c c e s s   t o   A C L   f i l e   " $ a c l U r l "   f o r   " $ r e s o u r c e U r l "   i s   f o r b i d d e n . ' , 
 
             ) ; 
 
 
 
         c a s e   R e s o u r c e S t a t u s . n o t E x i s t : 
 
             d e b u g P r i n t ( ' A C L   f i l e   " $ a c l U r l "   f o r   " $ r e s o u r c e U r l "   d o e s   n o t   e x i s t . ' ) ; 
 
 
 
         c a s e   R e s o u r c e S t a t u s . u n k n o w n : 
 
             t h r o w   E x c e p t i o n ( 
 
                 ' E r r o r   o c c u r r e d   w h e n   c h e c k i n g   s t a t u s   o f   A C L   f i l e   " $ a c l U r l "   f o r   " $ r e s o u r c e U r l " ' , 
 
             ) ; 
 
     } 
 
 } 
 
 
 
 / / /   D e l e t e   a   f i l e   a n d   i t s   a s s o c i a t e d   r e s o u r c e s ,   a f t e r   f i r s t   r e v o k i n g 
 
 / / /   e x t e r n a l   a c c e s s   t o   t h e   f i l e .   T h e   f i l e   w i t h   p a t h   [ f i l e P a t h ] , 
 
 / / /   i t s   A C L   f i l e ,   a n d   i t s   e n c r y p t i o n   k e y   ( i f   e x i s t s )   w i l l   b e   d e l e t e d . 
 
 / / /   T h e   p e r m i s s i o n   l o g s   o f   a n y   r e c i p i e n t s   t o   t h e   f i l e ,   w i l l   a l s o   b e 
 
 / / /   u p d a t e d   w i t h   a   l o g   l i n e   r e c o r d i n g   t h a t   p e r m i s s i o n s   h a v e   b e e n 
 
 / / /   r e v o k e d . 
 
 / / /   T h r o w s   a n   e x c e p t i o n   i f   t h e   f i l e   d o e s   n o t   e x i s t   o r   a n y   e r r o r   o c c u r s . 
 
 / / / 
 
 / / /   A r g u m e n t s : 
 
 / / / 
 
 / / /   -   [ f i l e P a t h ]   -   p a t h   o f   f i l e   t o   b e   d e l e t e d .   W h e r e   [ f i l e P a t h ]   i s   t h e 
 
 / / /   a p p   d a t a   d i r e c t o r y   a n d   t h e   f i l e n a m e . 
 
 / / /   -   [ c o n t e n t T y p e ]   -   t h e   t y p e   o f   c o n t e n t   o f   t h e   r e s o u r c e .   D e f a u l t : 
 
 / / /   [ R e s o u r c e C o n t e n t T y p e . t u r t l e T e x t ] . 
 
 / / /   -   [ i s K e y ]   -   f l a g   d e s c r i b i n g   w h e t h e r   t h e   f i l e   t o   b e   d e l e t e d   i s   a 
 
 / / /   s e c u r i t y   k e y .   U s e   t h i s   f l a g   i f   f i l e   i s   a   s e c u r i t y   k e y   t o   a v o i d 
 
 / / /   u n n e c e s s a r y   o p e r a t i o n s   t h a t   a r e   n o t   n e e d e d   t o   d e l e t e   a   k e y . 
 
 
 
 F u t u r e < v o i d >   d e l e t e F i l e ( 
 
     S t r i n g   f i l e P a t h ,   { 
 
     R e s o u r c e C o n t e n t T y p e   c o n t e n t T y p e   =   R e s o u r c e C o n t e n t T y p e . t u r t l e T e x t , 
 
     b o o l   i s K e y   =   f a l s e , 
 
 } )   a s y n c   { 
 
     i f   ( ! i s K e y )   { 
 
         / /   F i l e   t o   b e   d e l e t e d   ! =   k e y   = >   p e r f o r m   a l l   s t e p s 
 
 
 
         / /   R e v o k e   p e r m i s s i o n   t o   r e c i p i e n t s : 
 
         / /   t o   a v o i d   t h e   p e r m i s s i o n   l o g   o f   r e c i p i e n t s   s t i l l 
 
         / /   s h o w i n g   t h e   r e c i p i e n t   a s   h a v i n g   a c c e s s   t o   t h e 
 
         / /   f i l e   t h a t   i s   b e i n g   d e l e t e d 
 
         a w a i t   r e v o k e P e r m i s s i o n T o R e c i p i e n t s ( 
 
             f i l e N a m e :   f i l e P a t h , 
 
         ) ; 
 
 
 
         f i n a l   f i l e U r l   =   a w a i t   g e t F i l e U r l ( f i l e P a t h ) ; 
 
         a w a i t   d e l e t e R e s o u r c e ( f i l e U r l ,   c o n t e n t T y p e ) ; 
 
         a w a i t   d e l e t e A c l F o r R e s o u r c e ( f i l e U r l ) ; 
 
         i f   ( a w a i t   K e y M a n a g e r . h a s I n d i v i d u a l K e y ( f i l e U r l ) )   { 
 
             a w a i t   K e y M a n a g e r . r e m o v e I n d i v i d u a l K e y ( f i l e P a t h ) ; 
 
         } 
 
     }   e l s e   { 
 
         / /   F i l e   t o   b e   d e l e t e d   = =   k e y   = >   p e r f o r m   d e l e t e   o n l y 
 
         f i n a l   f i l e U r l   =   a w a i t   g e t F i l e U r l ( f i l e P a t h ) ; 
 
         a w a i t   d e l e t e R e s o u r c e ( f i l e U r l ,   c o n t e n t T y p e ) ; 
 
     } 
 
 } 
 
 
 
 / / /   D e l e t e   a n   e x t e r n a l   f i l e   w i t h   p a t h   [ f i l e U r l ]   a n d   t h e   s h a r e d   k e y 
 
 / / /   i f   t h e   f i l e   i s   e n c r y p t e d . 
 
 / / /   T h r o w s   a n   e x c e p t i o n   i f   t h e   f i l e   d o e s   n o t   e x i s t   o r   a n y   e r r o r   o c c u r s . 
 
 F u t u r e < v o i d >   d e l e t e E x t e r n a l F i l e ( 
 
     S t r i n g   f i l e U r l ,   { 
 
     R e s o u r c e C o n t e n t T y p e   c o n t e n t T y p e   =   R e s o u r c e C o n t e n t T y p e . t u r t l e T e x t , 
 
 } )   a s y n c   { 
 
     a w a i t   d e l e t e R e s o u r c e ( f i l e U r l ,   c o n t e n t T y p e ) ; 
 
     a w a i t   d e l e t e A c l F o r R e s o u r c e ( f i l e U r l ) ; 
 
     i f   ( a w a i t   K e y M a n a g e r . h a s S h a r e d I n d i v i d u a l K e y ( f i l e U r l ) )   { 
 
         f i n a l   w e b I d   =   a w a i t   A u t h D a t a M a n a g e r . g e t W e b I d ( ) ; 
 
         f i n a l   r e s U n i q u e I d   =   g e t U n i q u e I d R e s U r l ( f i l e U r l ,   w e b I d ! ) ; 
 
 
 
         a w a i t   K e y M a n a g e r . r e m o v e S h a r e d I n d i v i d u a l K e y ( f i l e U r l ,   r e s U n i q u e I d ) ; 
 
     } 
 
 
 
     / / /   a v :   N e e d   t o   a d d   t h e   f u n t i o n a l i t y   t o   r e m o v e   t h e   l o g   l i n e   f r o m   p e r m i s s i o n 
 
     / / /   l o g .   O t h e r w i s e ,   i t   w i l l   g i v e   a n   e r r o r . 
 
 } 
 
 
 
 / / /   G e t   d a t e   a n d   t i m e   f r o m   a   s t r i n g 
 
 S t r i n g   g e t D a t e T i m e ( S t r i n g   d a t e T i m e S t r )   { 
 
     f i n a l   d a t e T i m e   =   D a t e T i m e . p a r s e ( d a t e T i m e S t r ) ; 
 
     f i n a l   d a t e F o r m a t   =   D a t e F o r m a t ( ' d d / M M / y y y y   h h : m m : s s   a ' ) ; 
 
 
 
     r e t u r n   d a t e F o r m a t . f o r m a t ( d a t e T i m e ) ; 
 
 } 
 
 
 
 / / /   N o r m a l i s e   f i l e   p a t h   f o r   r e a d P o d / w r i t e P o d   o p e r a t i o n s . 
 
 / / / 
 
 / / /   H a n d l e s   b a c k w a r d   c o m p a t i b i l i t y   b y   c h e c k i n g   i f   t h e   f i l e P a t h   a l r e a d y   i n c l u d e s 
 
 / / /   t h e   a p p   d i r e c t o r y   p r e f i x ,   a n d   c o n s t r u c t s   t h e   a p p r o p r i a t e   n o r m a l i s e d   p a t h . 
 
 / / / 
 
 / / /   W h e n   b a s e P a t h   i s   n u l l   ( d e f a u l t   f o r   r e a d P o d / w r i t e P o d ) ,   u s e s   a p p n a m e / d a t a   a s   b a s e   p a t h . 
 
 / / / 
 
 / / /   [ f i l e P a t h ]   -   T h e   i n p u t   f i l e   p a t h 
 
 / / /   [ b a s e P a t h ]   -   T h e   b a s e   p a t h   t o   u s e   ( d e f a u l t s   t o   a p p n a m e / d a t a   w h e n   n u l l ) 
 
 / / / 
 
 / / /   R e t u r n s   t h e   n o r m a l i s e d   f i l e   p a t h . 
 
 / / / 
 
 / / /   E x a m p l e s : 
 
 / / /   -   ` n o r m a l i z e F i l e P a t h ( ' a b c . t t l ' ,   n u l l ) `   r e t u r n s   ` a p p n a m e / d a t a / a b c . t t l ` 
 
 / / /   -   ` n o r m a l i z e F i l e P a t h ( ' m o v i e s / a b c . t t l ' ,   n u l l ) `   r e t u r n s   ` a p p n a m e / d a t a / m o v i e s / a b c . t t l ` 
 
 / / /   -   ` n o r m a l i z e F i l e P a t h ( ' a p p n a m e / d a t a / k e y s . t t l ' ,   n u l l ) `   r e t u r n s   ` a p p n a m e / d a t a / k e y s . t t l ` 
 
 / / / 
 
 / / /   N o t e :   O n l y   ` a p p n a m e / d a t a / `   p a t h s   a r e   s u p p o r t e d   f o r   r e a d P o d / w r i t e P o d   o p e r a t i o n s . 
 
 
 
 F u t u r e < S t r i n g >   n o r m a l i z e F i l e P a t h ( S t r i n g   f i l e P a t h ,   S t r i n g ?   b a s e P a t h )   a s y n c   { 
 
     / /   N o r m a l i s e   p a t h   s e p a r a t o r s   f o r   c r o s s - p l a t f o r m   c o m p a t i b i l i t y . 
 
 
 
     f i n a l   n o r m a l i z e d I n p u t   =   f i l e P a t h . r e p l a c e A l l ( p a t h . s e p a r a t o r ,   ' / ' ) ; 
 
 
 
     / /   U s e   p r o v i d e d   p a t h   o r   d e f a u l t   t o   a p p n a m e / d a t a . 
 
 
 
     f i n a l   e f f e c t i v e B a s e P a t h   =   b a s e P a t h   = =   n u l l   | |   b a s e P a t h . t r i m ( ) . i s E m p t y 
 
             ?   a w a i t   g e t D a t a D i r P a t h ( ) 
 
             :   b a s e P a t h ; 
 
 
 
     / /   C h e c k   i f   p a t h   a l r e a d y   s t a r t s   w i t h   t h e   c o r r e c t   b a s e   p a t h   ( a p p n a m e / d a t a / ) . 
 
 
 
     i f   ( n o r m a l i z e d I n p u t . s t a r t s W i t h ( e f f e c t i v e B a s e P a t h ) )   { 
 
         / /   F u l l   p a t h   i s   a l r e a d y   p r e p e n d e d   ( a p p n a m e / d a t a / ) . 
 
 
 
         r e t u r n   n o r m a l i z e d I n p u t ; 
 
     }   e l s e   { 
 
         / /   P r e p e n d   t h e   b a s e   p a t h . 
 
 
 
         r e t u r n   [ e f f e c t i v e B a s e P a t h ,   n o r m a l i z e d I n p u t ] . j o i n ( ' / ' ) ; 
 
     } 
 
 } 
 
 
 
 / / /   C h e c k   i f   a   g i v e n   p a t h   s t r i n g   i s   a   d i r e c t o r y   o r   n o t 
 
 b o o l   i s D i r ( S t r i n g   p a t h )   { 
 
     i f   ( p a t h . e n d s W i t h ( ' / ' )   | |   ! p a t h . c o n t a i n s ( ' . ' ) )   { 
 
         r e t u r n   t r u e ; 
 
     }   e l s e   { 
 
         r e t u r n   f a l s e ; 
 
     } 
 
 } 
 
 
 
 / / /   G e n e r a t e   t h e   U R L   o f   r e s o u r c e   a c c o r d i n g   t o   i t s   p a t h   a n d   t h e   t y p e   o f   t h e   p a t h . 
 
 
 
 F u t u r e < S t r i n g >   g e n e r a t e R e s o u r c e U r l F r o m P a t h ( { 
 
     r e q u i r e d   S t r i n g   r e s o u r c e P a t h , 
 
     r e q u i r e d   P a t h T y p e   p a t h T y p e , 
 
     b o o l   i s F i l e   =   t r u e , 
 
 } )   a s y n c   { 
 
     f i n a l   f u n c   =   i s F i l e   ?   g e t F i l e U r l   :   g e t D i r U r l ; 
 
     s w i t c h   ( p a t h T y p e )   { 
 
         c a s e   P a t h T y p e . a b s o l u t e U r l : 
 
             r e t u r n   r e s o u r c e P a t h ; 
 
         c a s e   P a t h T y p e . r e l a t i v e T o P o d : 
 
             r e t u r n   a w a i t   f u n c ( r e s o u r c e P a t h ) ; 
 
 
 
         c a s e   P a t h T y p e . r e l a t i v e T o A p p : 
 
             r e t u r n   a w a i t   f u n c ( [ a p p D i r N a m e ,   r e s o u r c e P a t h ] . j o i n ( ' / ' ) ) ; 
 
 
 
         c a s e   P a t h T y p e . r e l a t i v e T o D a t a : 
 
             r e t u r n   a w a i t   f u n c ( [ a w a i t   g e t D a t a D i r P a t h ( ) ,   r e s o u r c e P a t h ] . j o i n ( ' / ' ) ) ; 
 
     } 
 
 } 
 
 
 
 / / /   E x t r a c t   r e s o u r c e   p a t h   f r o m   i t s   U R L 
 
 
 
 F u t u r e < S t r i n g >   e x t r a c t R e s o u r c e P a t h F r o m U r l ( 
 
     S t r i n g   r e s o u r c e U r l ,   { 
 
     b o o l   i s F i l e   =   t r u e , 
 
 } )   a s y n c   { 
 
     / /   S e e   h t t p s : / / a p i . d a r t . d e v / d a r t - c o r e / U r i - c l a s s . h t m l   f o r   d e t a i l s 
 
 
 
     f i n a l   s e g m e n t s   =   U r i . p a r s e ( r e s o u r c e U r l ) . p a t h S e g m e n t s ; 
 
 
 
     f i n a l   p a t h   =   s e g m e n t s . g e t R a n g e ( 1 ,   s e g m e n t s . l e n g t h ) . j o i n ( ' / ' ) ; 
 
 
 
     r e t u r n   ! ( i s F i l e   | |   p a t h . e n d s W i t h ( ' / ' ) )   ?   ' $ p a t h / '   :   p a t h ; 
 
 } 
 
 